none
通过代码删除Menu控件的菜单的问题 RRS feed

  • 问题

  • 通过代码删除Menu控件的菜单的问题

    环境:Visual Studio 2010; ASP.NET 4.0 ;

    需求:希望通过代码删除MENU控件中特定的菜单项, 但始终不成功;

    代码如下:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace WebIMS
    {
        public partial class Site1 : System.Web.UI.MasterPage
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (Session["Session_Account"] == null) //如果没有登录
                {
                    Response.Redirect("/Index.aspx");
                }

                if (!IsPostBack) //如果是首次加载页面
                {
                    MenuItem Main = new MenuItem(); Main.Text = "主界面"; Main.NavigateUrl = "~/Main_Site.aspx";
                    Menu1.Items.Add(Main);

                    MenuItem Order_Create = new MenuItem(); Order_Create.Text = "创建订单"; Order_Create.NavigateUrl = "~/Order_Create.aspx";
                    Menu1.Items.Add(Order_Create);

                    MenuItem Order_Search = new MenuItem(); Order_Search.Text = "订单查询"; Order_Search.NavigateUrl = "~/Order_Search.aspx";
                    Menu1.Items.Add(Order_Search);

                    MenuItem Order_Processing = new MenuItem(); Order_Processing.Text = "订单审核"; Order_Processing.NavigateUrl = "~/Order_Processing.aspx";
                    Menu1.Items.Add(Order_Processing);

                    MenuItem Order_Admin = new MenuItem(); Order_Admin.Text = "订单管理"; Order_Admin.NavigateUrl = "~/Order_Admin.aspx";
                    Menu1.Items.Add(Order_Admin);

                    MenuItem EditPassWord = new MenuItem(); EditPassWord.Text = "修改密码"; EditPassWord.NavigateUrl = "~/EditPassWord.aspx";
                    Menu1.Items.Add(EditPassWord);

                    MenuItem Manage = new MenuItem(); Manage.Text = "系统管理";
                    MenuItem Manage_A = new MenuItem(); Manage_A.Text = "邮件设置"; Manage_A.NavigateUrl = "~/SysEmail.aspx";
                    MenuItem Manage_B = new MenuItem(); Manage_B.Text = "账户管理"; Manage_B.NavigateUrl = "~/Account_Manage.aspx";
                    Manage_A.ChildItems.Add(Manage_A);
                    Manage.ChildItems.Add(Manage_A);

                    Manage_B.ChildItems.Add(Manage_B);
                    Manage.ChildItems.Add(Manage_B);

                    Menu1.Items.Add(Manage);

                    //按权限 显示菜单
                    if (Session["Right_Sys_Manage"].ToString() != "True")
                    {
                   
                        this.Menu1.Items.RemoveAt(0);

                    }
                    if (Session["Order_Create"].ToString() != "True")
                    {

                    }
                    if (Session["Order_Search"].ToString() != "True")
                    {

                    }
                    if (Session["Order_Processing"].ToString() != "True")
                    {

                    }
                    if (Session["Order_Admin"].ToString() != "True")
                    {

                    }

                }

               
                
            }
        }
    }

    2013年2月25日 11:58

全部回复