zoukankan      html  css  js  c++  java
  • Menu控件绑定菜单代码

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using NUCTechnologyPark.UIControl;
    using System.Data;
    using NUCTechnologyParkBLL;

    namespace NUCTechnologyPark.UserControl
    {
        public partial class Head : BaseUserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                BindMenu();
            }
            //从数据库查询绑定菜单
            public void BindMenu()
            {

                int Sign = 0;
                DataTable dtm = B_News.BindSignMenuName(Sign); //需修改查询出所有数据
                string parentMenuFilter = "1=1";
                BindMenuItems(dtm, parentMenuFilter);

            }
            //绑定一级栏目
            public void BindMenuItems(DataTable table, string strParentNodeFilter)
            {
                //MenuItem DMenuNode = new MenuItem();
                //DMenuNode.Text ="  "+"首页";
                //DMenuNode.Value = "109";
                //DMenuNode.NavigateUrl = "../Default.aspx";
                //DMenuNode.Enabled = true;
                //DMenuNode.Selectable = true;

                //this.Menu1.Items.Add(DMenuNode);
                DataRow[] drs = table.Select(strParentNodeFilter);
                foreach (DataRow dr in drs)
                {
                    MenuItem MenuNode = new MenuItem();
                    if (dr["Menu_Pk"].ToString() == "109")
                    {
                        //Menu1.Items[0].Text = "<a style=\"你的样式\" class=\"你的class\">文本</a>";

                        MenuNode.Text = "首页";
                        MenuNode.Value = "109";
                        MenuNode.NavigateUrl = "../Default.aspx";
                        MenuNode.Enabled = true;
                        MenuNode.Selectable = true;

                    }
                    else
                    {
                        MenuNode.Text = dr["Class_Name"].ToString();
                        MenuNode.Value = dr["Menu_Pk"].ToString();
                        MenuNode.NavigateUrl = dr["MUrl"].ToString();
                        MenuNode.Enabled = true;
                        MenuNode.Selectable = true;
                    }
                    this.Menu1.Items.Add(MenuNode);
                    //设置节点是否可以选择和点击                    
                    if (dr["Menu_Pk"].ToString() != "109")
                    {
                        DataTable tab = B_News.GetKindMenuName(int.Parse(dr["Menu_Pk"].ToString()));      //根据栏目Pk查询出二级栏目
                        AddChildMenu(MenuNode, tab);
                    }

                }
            }
            //绑定二级栏目
            public void AddChildMenu(MenuItem node, DataTable tab)
            {


                for (int i = 0; i < tab.Rows.Count; i++)
                {
                    DataRow dr = tab.Rows[i];
                    MenuItem ChildNode = new MenuItem();
                    ChildNode.Text = "<span style=\"color:Black;Z-Index:-1;border-bottom:1px solid Menu ;display:inline-block;Border-style:none;100px;height:22px;border-bottom:1px solid Menu;padding-top:5px;\"  >" + dr["Class_Name"].ToString() + "</span>";
                    ChildNode.Value = dr["Menu_Pk"].ToString();
                    ChildNode.NavigateUrl = dr["Url"].ToString();
                    ChildNode.Enabled = true;
                    ChildNode.Selectable = true;
                    node.ChildItems.Add(ChildNode);
                    //AddChildMenu(ChildNode, int.Parse(dr["Menu_Pk"].ToString()), tab);
                }

            }
        }
    }

  • 相关阅读:
    Chrome Extension 扩展程序 小白入门
    gulp 打包报错:ReferenceError: internalBinding is not defined
    error in static/js/xxx.js from UglifyJs Unpected token: punc() [static/js/xxx.js]
    ES6-
    浏览器的渲染原理(转载)
    nodeType、nodeName和nodeValue
    浏览器 HTTP 协议缓存机制详解
    JS函数的上下文环境
    ready和onload的区别
    自定义事件
  • 原文地址:https://www.cnblogs.com/lykbk/p/Menu.html
Copyright © 2011-2022 走看看