2013-02-25 14 views
5

In Pagina master:Come disattivare specifica voce di menu dal menu di controllo in asp.net codice C# dietro

<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" Width="60%" 
      BackColor="#336699" Font-Bold="True" 
      ForeColor="White"> 
      <StaticMenuStyle BackColor="#336699" /> 
      <StaticSelectedStyle BackColor="#336699" /> 
      <StaticMenuItemStyle BackColor="#336699" /> 
      <DynamicHoverStyle BackColor="#336699" /> 
      <DynamicMenuStyle BackColor="#336699" /> 
      <DynamicMenuItemStyle BackColor="#336699" /> 
      <StaticHoverStyle BackColor="#336699" /> 
     <Items> 
      <asp:MenuItem Text="Dashboard" NavigateUrl="~/Timecard/Dashboard.aspx"> 
      </asp:MenuItem> 
          <asp:MenuItem Text="Timecard" NavigateUrl="~/Timecard/TimeCardEntry.aspx"> 
      </asp:MenuItem> 
          <asp:MenuItem Text="Reports"> 
          <asp:MenuItem Text="Employee Time card Report" NavigateUrl="~/Reports/Employee_Timecard .aspx"></asp:MenuItem> 
          <asp:MenuItem Text="Employee Leave Detail Report" NavigateUrl="~/Reports/Employee Leave Details.aspx"></asp:MenuItem> 
          <asp:MenuItem Text="Project wise Report" NavigateUrl="~/Reports/ProjectWise.aspx"></asp:MenuItem> 
      </asp:MenuItem> 
          <asp:MenuItem Text="Master"> 
           <asp:MenuItem Text="Company" NavigateUrl="~/Admin/CompanyList.aspx"></asp:MenuItem> 
           <asp:MenuItem Text="Designation" NavigateUrl="~/Admin/DesignationList.aspx"></asp:MenuItem> 
           <asp:MenuItem Text="Task" NavigateUrl="~/Admin/TaskList.aspx"></asp:MenuItem> 
           <asp:MenuItem Text="Project" NavigateUrl="~/Admin/ProjectList.aspx"></asp:MenuItem> 
           <asp:MenuItem Text="Employee" NavigateUrl="~/Admin/EmployeeList.aspx"></asp:MenuItem> 
           <asp:MenuItem Text="Employee Transfer/Promotion" NavigateUrl="~/Admin/EmployeeTransferList.aspx"></asp:MenuItem> 
          <asp:MenuItem Text="Holiday" NavigateUrl="~/Admin/HolidayList.aspx"></asp:MenuItem> 
      </asp:MenuItem> 
     </Items> 
     </asp:Menu> 

Voglio disattivare Rapporti e menu Master nel codebehind. Devo controllare che fosse admin o meno. se l'utente è nello stato admin significa che devono essere visualizzate tutte le voci di menu, se l'utente non è un amministratore significa che devo impostare visible = false per il report e il menu principale. Mi aiuti per favore.

+0

prova usando Enabled = proprietà "false" per menuitem .. – coder

risposta

2

ho avuto la soluzione:

protected void Page_Load(object sender, EventArgs e) 
    { 
     if (strAdmin == "False") 
     { 
      MenuItem mnuItem = Menu1.FindItem("Reports"); // Find particular item 
      Menu1.Items.Remove(mnuItem); 
      MenuItem mnuItem1 = Menu1.FindItem("Master"); // Find particular item 
      Menu1.Items.Remove(mnuItem1); 
      Menu1.Width = Unit.Percentage(30); 
     } 
    } 
6

Prova come qui di seguito funzionerà ...

if(UserStatus != "Admin") 
{ 
Menu1.Items.Remove(Menu1.FindItem("Reports")); 
Menu1.Items.Remove(Menu1.FindItem("Master")); 
} 

Se il menu è in pagina master Allora prova come qui di seguito ...

var menu = Page.Master.FindControl("Menu1") as Menu; 
if (menu != null) 
{ 
menu.Items.Remove(menu.FindItem("Reports")); 
menu.Items.Remove(menu.FindItem("Master")); 
}