【问题标题】:How to show the NavigationMenu after you hide it in ASP.NET?在 ASP.NET 中隐藏 NavigationMenu 后如何显示它?
【发布时间】:2012-07-20 18:43:10
【问题描述】:

我需要让一些 NavigationMenu 项目只对某些用户可见。 就我而言,我需要将其中 2 个设置为仅供管理员使用。

我搜索了谷歌,我发现了一个有效的命令:

NavigationMenu.Items.Remove(NavigationMenu.FindItem("这里是我需要删除的菜单的名称"));

到这里为止,一切正常。 但是我需要使用哪个命令才能使其再次可用?

请帮助我。提前谢谢 ;)

public partial class SiteMaster : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        NavigationMenu.Items.Remove(NavigationMenu.FindItem("Employers"));

        if (Matrix.UserLoggedId == Guid.Empty)
        {

            hlLogin.Visible = true;
            lblUsername.Visible = false;
            lnkLogout.Visible = false;
        }
        else
        {
            // here goes the code to add the menu
            hlLogin.Visible = false;
            lblUsername.Visible = true;
            lnkLogout.Visible = true;

            Marin.Employee.DetailsDataTable emp = Matrix.GetEmployeeByUniqueId(Matrix.UserLoggedId);
            if (emp.Rows.Count > 0)
            {

                lblUsername.Text = emp.Rows[0]["Firstname"].ToString();


                bool isAdmin =Convert.ToBoolean(emp.Rows[0]["isAdmin"]);
                if (isAdmin)
                {
                    //here goes the code to show the menu
                }
                else
                {

                   NavigationMenu.Items.Remove(NavigationMenu.FindItem("Employers"));
                }
            }

        }

    }

【问题讨论】:

    标签: asp.net menu navigation


    【解决方案1】:

    试试这个,用正确的值替换 x。

    var mi = new MenuItem(x,x,x,x)
    NavigationMenu.Items.Add(mi);
    

    有关 MenuItem 的更多信息,请查看此 -

    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.menuitem.aspx

    【讨论】:

    • 这似乎是解决方案,因为它显示和隐藏菜单,但是当我以管理员身份登录并单击菜单时,它没有执行任何操作。你介意我把代码贴在这里看看我的错误可能在哪里吗?谢谢 ;)
    • 你用过new Manuitem("label here","","","url here");
    • 不,我没有使用它,没有使用任何网址。
    • Yesssssssssss,我做到了....非常感谢!我添加了我的导航菜单必须重定向我的页面的 url,它运行良好 :) 非常感谢@rs
    猜你喜欢
    • 1970-01-01
    • 2011-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    • 2018-09-12
    • 2013-12-04
    • 1970-01-01
    相关资源
    最近更新 更多