0
<asp:Menu ID="Menu1" runat="server"  Orientation="Horizontal" StaticSubMenuIndent="10px"
    <asp:MenuItem Text="DashBoard"></asp:MenuItem>
    <asp:MenuItem Text="Project">
        <asp:MenuItem Text="Config Project"></asp:MenuItem>
        <asp:MenuItem Text="Task"></asp:MenuItem>
    </asp:MenuItem>

    <asp:MenuItem Text="Employees">
        <asp:MenuItem  Text="EMS"></asp:MenuItem>
        <asp:MenuItem Text="TimeSheet">
    <asp:MenuItem Text="Period"></asp:MenuItem>
    <asp:MenuItem Text="Report"></asp:MenuItem>
    </asp:MenuItem>
    </asp:MenuItem
</asp:menu>

I am new in C#..how can i hide Task,Report menu items from menu list on page load ,considering this menu in master page.I tried searching for similar question but didn't get right solution!

D Stanley
  • 149,601
  • 11
  • 178
  • 240
TheCode
  • 341
  • 1
  • 4
  • 10
  • 1
    Give the MenuItem you want to hide an ID, access it from the codebehind, set it to invisible. I'm rusty which is why I didn't post this as an answer, but I think that's the general process. You may have to specify your .cs file as the codebehind in the ASP file. Google for C# codebehind – KyleM Apr 29 '13 at 21:58
  • Maybe this related question can help you http://stackoverflow.com/a/4939114/541432 – elvin Apr 29 '13 at 21:59
  • @KyleM Menuitem dont have any id – TheCode Apr 29 '13 at 22:13
  • @elvin through your provided link m able to remove/hide first menu items i.e Dashboard,Employee,Project but not there sub items – TheCode Apr 29 '13 at 22:14
  • This is focused on removing, but you can see how you can access children of children in the answers: http://stackoverflow.com/questions/430573/hide-an-asp-net-menu-item - so something like `Menu1.Items[1].ChildItems[1].Hidden = true;` - it isn't very flexible, but it'll work. – Tim Hobbs Apr 30 '13 at 22:31
  • here is the solution - Concept - http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.menuitem.childitems.aspx Through db - http://www.codeshode.com/2011/07/display-hierarchical-data-with-menu.html – TheCode May 06 '13 at 22:28

2 Answers2

0

This is an old question, but for reference, here is the solution that I use:

var menuItems = NavigationMenu.Items;
var projectMenuItem = menuItems.Cast<MenuItem>().First(p => p.Text == "Project");
var subItem = projectMenuItem.Cast<MenuItem>().First(p => p.Text == "Task");
projectMenuItem.ChildItems.Remove(subItem);

It's not pretty, but it works. Improvements welcome.

Raithlin
  • 1,764
  • 10
  • 19