zoukankan      html  css  js  c++  java
  • DroDownList控件多级下拉菜单

    后台代码:

        /// <summary>
            /// 绑定下拉菜单
            /// </summary>
            private void BindDropList()
            {
                DataTable dt = bacManage.GetAllArticleCategory();
                CreateLevelDropDown(drpCategoryId, dt);
            }
    
            /// <summary>
            /// 创建分级下拉框
            /// </summary>
            /// <param name="ddlst"></param>
            /// <param name="dt"></param>
            private void CreateLevelDropDown(DropDownList ddlst, DataTable dt)
            {
                System.Collections.ArrayList allItems = new ArrayList();
                DataRow[] rows = dt.Select("[parent]=" + 0);
                foreach (DataRow row in rows)
                    CreateLevelDropDownAssistant(dt, ref   allItems, row, string.Empty);
    
                ListItem[] items = new ListItem[allItems.Count];
                allItems.CopyTo(items);
                ddlst.Items.AddRange(items);
            }
    
            /// <summary>
            /// 设置下拉列表分级格式
            /// </summary>
            /// <param name="dt"></param>
            /// <param name="items"></param>
            /// <param name="parentRow"></param>
            /// <param name="curHeader"></param>
            private void CreateLevelDropDownAssistant(DataTable dt, ref   ArrayList items, DataRow parentRow, string curHeader)
            {
                ListItem newItem = new ListItem(curHeader + parentRow["name"].ToString(), parentRow["category_id"].ToString());
                items.Add(newItem);
                parentRow.Delete();
    
                DataRow[] rows = dt.Select("[parent]='" + 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("", "") + "");
            }

        /// <summary>
            /// 绑定下拉菜单
            /// </summary>
            private void BindDropList()
            {
                DataTable dt = bacManage.GetAllArticleCategory();
                CreateLevelDropDown(drpCategoryId, dt);
            }

            /// <summary>
            /// 创建分级下拉框
            /// </summary>
            /// <param name="ddlst"></param>
            /// <param name="dt"></param>
            private void CreateLevelDropDown(DropDownList ddlst, DataTable dt)
            {
                System.Collections.ArrayList allItems = new ArrayList();
                DataRow[] rows = dt.Select("[parent]=" + 0);
                foreach (DataRow row in rows)
                    CreateLevelDropDownAssistant(dt, ref   allItems, row, string.Empty);

                ListItem[] items = new ListItem[allItems.Count];
                allItems.CopyTo(items);
                ddlst.Items.AddRange(items);
            }

            /// <summary>
            /// 设置下拉列表分级格式
            /// </summary>
            /// <param name="dt"></param>
            /// <param name="items"></param>
            /// <param name="parentRow"></param>
            /// <param name="curHeader"></param>
            private void CreateLevelDropDownAssistant(DataTable dt, ref   ArrayList items, DataRow parentRow, string curHeader)
            {
                ListItem newItem = new ListItem(curHeader + parentRow["name"].ToString(), parentRow["category_id"].ToString());
                items.Add(newItem);
                parentRow.Delete();

                DataRow[] rows = dt.Select("[parent]='" + 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("┗", "┣") + "┗");
            }

  • 相关阅读:
    js 的防抖与节流
    Vue---图形二维码、rules校验规则、el-dialog展示图片
    vue ----弹框
    vue的背景加载--旋转*号
    利用ES6新特性将时间戳转换为yyyy-mm-dd格式
    路由守卫之离开守卫
    Java的运行环境与开发环境
    list<map<string,object>> 按照某字段排序
    没有CSRF保护的HTML表单 漏洞解决办法
    通过mybatis-plus的分页插件,实现分页
  • 原文地址:https://www.cnblogs.com/acoll/p/3834193.html
Copyright © 2011-2022 走看看