• C#递归在dropdownlist显示树状


    /// <summary>
        /// 绑定文件分类
        /// </summary>
        public void bind()
        {
            //获取数据集
            DataSet ds = new DataSet();
            ds = ec.ExecuteSelectCmmond("select * from t_Column where U_UserID='" + HttpContext.Current.Request.Cookies["NameID"].Value + "'", ds);
            BindingCWAList(DropDownList1, ds);
        }
        private void BindingCWAList(DropDownList ddlID, DataSet ds) //ddlID是DropDownList控件的ID
        {
            DropDownList1.Items.Clear();
            //此处创建顶极分类,Value=0(如不需要,可以删除此行)
            ddlID.Items.Add(new ListItem("请选择目录", "0"));
            InitList(ddlID, 0, ds, "");
        }


        private void InitList(DropDownList ddlID, int parentID, DataSet catagoryDS, string indent)
        {
            //Select后边的是DataSet里面的列名
            System.Data.DataRow[] currRows = catagoryDS.Tables[0].Select("ColumnFatherld=" + parentID.ToString(), "ColumnFatherld ASC");
            int count = currRows.Length;
            DataRow catagoryRow;
            for (int i = 0; i < count; i++)
            {
                catagoryRow = currRows[i];
                System.Web.UI.WebControls.ListItem item = new System.Web.UI.WebControls.ListItem(indent + catagoryRow      ["ColunmnName"].ToString(), catagoryRow["ColumnId"].ToString());
                ddlID.Items.Add(item);
                InitList(ddlID, Int32.Parse(catagoryRow["ColumnId"].ToString()), catagoryDS, indent + "……");
            }
        }

  • 相关阅读:
    sequelize 批量添加和更新数据 bulkCreate
    js 线程和进程的关系
    mysql 索引 笔记1
    mysql 主键
    loj2292 「THUSC 2016」成绩单
    loj2291 「THUSC 2016」补退选
    cf984c Finite or not?
    cf984e Elevator
    loj2540 「PKUWC 2018」随机算法
    luoguT30204 偷上网
  • 原文地址:https://www.cnblogs.com/windy224/p/2150196.html
Copyright © 2020-2023  润新知