• dropdownlist无限级分组显示


    List<column_Model> ddlList = new List<column_Model>();

            /// <summary>
            /// 绑定父栏目
            /// </summary>
            /// <param name="ddlColumn">栏目下拉控件</param>
            public void BindFather(DropDownList ddlColumn)
            {
                ddlColumn.Items.Add(new ListItem("请选择栏目...", "0"));
                ddlList = DAL.column.Select();
                if (ddlList!=null)
                {
                    foreach (column_Model item in ddlList)
                    {
                        if (item.parentId=="0")
                        {
                            string columnId = item.columnId;
                            string columnName = item.columnName;
                            columnName = "" + columnName;
                            ddlColumn.Items.Add(new ListItem(columnName, columnId));
                            string sonParentId = columnId;
                            string blank ="├";
                            BindNode(sonParentId, blank, ddlColumn);
                        }
                    }
                    ddlColumn.DataBind();
                }
            }

            /// <summary>
            /// 绑定子栏目
            /// </summary>
            /// <param name="parentid">父栏目ID</param>
            /// <param name="blank">间隔符号</param>
            /// <param name="ddlColumn">栏目下拉控件</param>
            public void BindNode(string parentid, string blank, DropDownList ddlColumn)
            {
                List<column_Model> sonList = getChild(parentid);
                foreach (column_Model item in sonList)
                {
                    string columnId = item.columnId;
                    string columnName = item.columnName;
                    columnName = blank + columnName;
                    ddlColumn.Items.Add(new ListItem(columnName, columnId));
                    string sonParentId = columnId;
                    string blank2 = blank + "─";
                    BindNode(sonParentId, blank2, ddlColumn);
                }
            }

            /// <summary>
            /// 根据父栏目ID获取子栏目
            /// </summary>
            /// <param name="parentId">父栏目ID</param>
            /// <returns></returns>
            public List<column_Model> getChild(string parentId)
            {
                List<column_Model> sonList = new List<column_Model>();
                foreach (column_Model item in ddlList)
                {
                    if (item.parentId==parentId)
                    {
                        sonList.Add(item);
                    }
                }
                return sonList;
            }
  • 相关阅读:
    GOF之单例模式
    C#面向对象设计模式纵横谈课堂笔记
    Oracle事务
    Oracle游标
    pl/sql(一)
    pl/sql(二)
    pl/sql(三)
    Oracle用户管理
    Oracle视图
    Oracle函数
  • 原文地址:https://www.cnblogs.com/top5/p/1556163.html
Copyright © 2020-2023  润新知