zoukankan      html  css  js  c++  java
  • DropDownList 下拉无限极分类代码

           #region 无限极分类;
            /// <summary>
            /// 绑定DropDownList;
            /// </summary>
            protected void BindDropdownList()
            {
                DataTable dt = new DataTable();
                dt = bllClass.GetAllList().Tables[0];
                CreateLevelDropDown(ddlType, dt);
                //ddlType.Items.Insert(ddlType.Items.Count, new ListItem("——此类为根类——", "0"));
                ListItem tempItemNull = ddlType.Items.FindByValue("0");
            }
            /// <summary>
            ///实现无限极分类;
            /// </summary>
            /// <param name="ddlst"></param>
            /// <param name="dt"></param>
            protected void CreateLevelDropDown(DropDownList ddlst, DataTable dt)
            {
                ArrayList allItems = new ArrayList();
                DataRow[] rows = dt.Select("ParentId=" + 0);
                foreach (DataRow row in rows)
                {
                    CreateLevelDropDownAssistant(dt, ref allItems, row, string.Empty);
                    ListItem[] items = new ListItem[allItems.Count];
                    allItems.CopyTo(items);
                    ddlst.Items.Clear();
                    ddlst.Items.AddRange(items);
                }
            }
            private void CreateLevelDropDownAssistant(DataTable dt, ref   ArrayList items, DataRow parentRow, string curHeader)
            {
                ListItem newItem = new ListItem(curHeader + parentRow["ClassName"].ToString(), parentRow["ClassId"].ToString());
                items.Add(newItem);
                DataRow[] rows = dt.Select("ParentId=" + newItem.Value);
                for (int i = 0; i < rows.Length - 1; i++)
                    CreateLevelDropDownAssistant(dt, ref   items, rows[i], curHeader.Replace("┣", "┃").Replace("┗", "┣") + "┣");

                if (rows.Length > 0)
                    CreateLevelDropDownAssistant(dt, ref   items, rows[rows.Length - 1], curHeader.Replace("┣", "┃").Replace("┗", "┣") + "┗");
            }
            #endregion

  • 相关阅读:
    js/jsp常用记录(一)
    Oracle 存储过程的基本语法 及注意事项
    PL/SQL Developer使用技巧、快捷键
    Zookeeper的功能以及工作原理
    牛客网PAT练兵场-德才论
    牛客网PAT练习场-数素数
    牛客网PAT练兵场-D进制的A+B
    牛客网PAT练习场-个位数的统计
    牛客网PAT练习场-数字分类
    牛客网PAT练习场-A+B和C
  • 原文地址:https://www.cnblogs.com/TNSSTAR/p/2390747.html
Copyright © 2011-2022 走看看