zoukankan      html  css  js  c++  java
  • 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;
            }
  • 相关阅读:
    WPF自定义路由事件
    一文看懂微服务背后的技术演进与应用实践
    云原生消息、事件、流超融合平台——RocketMQ 5.0 初探
    KubeVela 1.1 发布,开启混合环境应用交付新里程碑
    Facebook宕机背后,我们该如何及时发现DNS问题
    Apache Flink 在汽车之家的应用与实践
    新一代容器平台ACK Anywhere,来了
    Serverless 工程实践 | Serverless 应用优化与调试秘诀
    OpenKruise 如何实现应用的可用性防护?
    国家网络安全宣传周:勒索病毒利如刀,上网备好技能包
  • 原文地址:https://www.cnblogs.com/top5/p/1556163.html
Copyright © 2011-2022 走看看