我需要使某些NavigationMenu项仅对某些用户可见。在我的情况下,我需要使其中2个只对管理员可用。
我搜索了谷歌,发现了一个有效的命令:
NavigationMenu.Items.Remove(NavigationMenu.FindItem("此处为我需要删除的菜单名称"));
到这里为止,一切都很好。但是,我需要使用哪个命令才能使其再次可用?
请帮帮我。提前Thnx;)
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"));
}
}
}
}
试试这个,用正确的值替换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