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

  • 相关阅读:
    iOS开发应用设置及用户默认设置【2、读取应用中的设置】
    iOS开发应用设置及用户默认设置【1、bundle的运用】
    iOS开发中的4种数据持久化方式【二、数据库 SQLite3、Core Data 的运用】
    iOS开发中的4种数据持久化方式【一、属性列表与归档解档】
    iOS开发编译报错、常见问题(实时更新)
    js window.location用法
    canvas 时钟
    java File处理
    servletjspEL 表达式
    Linux(centos 7)配置tomcat8、JDK1.8、lighttpd、ngnix、mysql
  • 原文地址:https://www.cnblogs.com/TNSSTAR/p/2390747.html
Copyright © 2011-2022 走看看