asp.net DropDownList中内容伪树状展示

        #region "绑定区域下拉菜单"
        /// <summary>
        /// 绑定树形节点
        /// </summary>
        public void BindAreaDropDownList()
        {
            DataTable dt = new AreaBLL().GetData("", " Orderby ASC");
            Areaddl.Items.Add(new ListItem("请选择", "0"));
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    if (!DBNull.Value.Equals(row["ParentID"]) && row["ParentID"].ToString() == "0")//绑定根节点
                    {
                        this.Areaddl.Items.Add(new ListItem(row["Name"].ToString(), row["ID"].ToString()));
                        this.bindDropChildItem(this.Areaddl, dt, row["ID"].ToString(), 1);
                    }
                }
            }
        }


        /// <summary>
        /// 绑定子节点
        /// </summary>
        /// <param name="drop">下拉菜单</param>
        /// <param name="arealist">查询到的数据集</param>
        /// <param name="id">当前的父节点</param>
        /// <param name="length">长度</param>
        public void bindDropChildItem(DropDownList drop, DataTable dt, string id, int length)
        {
            DataRow[] rows = dt.Select("ParentID='" + id + "'", " orderby ASC");//取出id子节点进行绑定
            for (int i = 0; i < rows.Length; i++)
            {
                this.Areaddl.Items.Add(new ListItem(SpaceLength(length) + rows[i]["Name"].ToString(), rows[i]["ID"].ToString()));
                this.bindDropChildItem(drop, dt, rows[i]["ID"].ToString(), length + 1);//空白数目加1
            }
        }

        /// <summary>
        /// 子节点前面的空白数
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        protected string SpaceLength(int i)
        {
            string space = "";
            for (int j = 0; j < i; j++)
            {
                space += " ";//注意这里的空白是智能abc输入法状态下的v11字符;
            }
            return space;
        }

        #endregion



你可能感兴趣的:(String,null,输入法)