menu控件的使用

 在.net的导航控件中,我用的最多的是TreeView控件,今天无意间用到了menu控件,感觉挺好的.写出来当作笔记吧!

前台代码:
<asp:Menu ID="Menu1" runat="server" BackColor="#FFFBD6" DynamicHorizontalOffset="2"
             ForeColor="#990000" Height="187px" Orientation="Horizontal" StaticSubMenuIndent="10px"
             Style="font-size: 8pt; font-family: Verdana; display: block; background-position-x: center; background-attachment: scroll; background-image: url(img/Alter.jpg); visibility: visible; color: #ff3399; background-repeat: repeat-x; position: static; background-color: #99ff00; text-align: center;" Font-Names="Verdana" Font-Size="0.8em"  Width="594px" OnMenuItemClick="Menu1_MenuItemClick">
             <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
             <DynamicHoverStyle BackColor="#990000" ForeColor="White" />
             <DynamicMenuStyle BackColor="#FFFBD6" BorderColor="White" BorderStyle="Solid" BorderWidth="1px" />
             <StaticSelectedStyle BackColor="#FFCC66" />
             <DynamicSelectedStyle BackColor="#FFCC66" />
             <StaticHoverStyle BackColor="#990000" ForeColor="White" />
             <DynamicMenuItemStyle BackColor="#B5C7DE" Font-Names="Verdana" Font-Size="8pt" BorderColor="White" BorderStyle="Solid" BorderWidth="1px" HorizontalPadding="5px" VerticalPadding="2px" />
         </asp:Menu>

后台代码:
 #region 页面初始化
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            PR.BLL.menu.A_Menu bll = new PR.BLL.menu.A_Menu();
            DataSet ds = bll.GetList();
            CreateMenu(1, (MenuItem)null, ds);
        }
    }
    #endregion
    #region 递归生成横向菜单
    public void CreateMenu(int ParentID, MenuItem tempItem, DataSet ds)
    {
        DataView dvMenu = new DataView(ds.Tables[0]);
        //过滤ParentID,得到当前菜单的所有子节点
        dvMenu.RowFilter = "[MenuParentId] = " + ParentID;

        foreach (DataRowView Row in dvMenu)
        {
            if (tempItem == null)
            {     //添加根节点
                MenuItem Node = new MenuItem();
                //节点的文本
                Node.Text = Row["FMenuName"].ToString();
                //节点旁边的图片
               // Node.ImageUrl = "img/" + Row["MenuImage"].ToString();
                //有子菜单时的图片
                //Node.PopOutImageUrl = "img/02.gif"; 
                this.Menu1.Items.Add(Node);
                CreateMenu(Int32.Parse(Row["Fid"].ToString()), Node, ds);//再次递归
            }
            else
            {    //添加当前节点的子节点
                MenuItem Node = new MenuItem();
                Node.Text = Row["FMenuName"].ToString();
                //点击节点后的连接地址
                Node.NavigateUrl = Row["Url"].ToString();
                //Node.ImageUrl = "Image/" + Row["MenuImage"].ToString();
                //Node.Target = Row["left"].ToString();
                tempItem.ChildItems.Add(Node);
                CreateMenu(Int32.Parse(Row["Fid"].ToString()), Node, ds); //再次递归
            }
        }
    }
    #endregion
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值