Click here to Skip to main content
15,909,242 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my menu code. and "Employee wise Report" is my submenu under "Report" menu.Now how can i hide this submenu when i load load my site?

ASP.NET
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
                    <Items>
                        <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
                        <asp:MenuItem NavigateUrl="~/Report.aspx" Text="Report">
                            <asp:MenuItem Text="Employee wise Report" Value="Employee wise Report"></asp:MenuItem>
                            <asp:MenuItem  Text="Date Wise Report" Value="Date Wise Report"></asp:MenuItem>
                            <asp:MenuItem Text="Brand wise Report" Value="Brand"></asp:MenuItem>
                        </asp:MenuItem>
                    </Items>
                </asp:Menu>


What I have tried:

I have tried
NavigationMenu.Items[1].ChildItems[0].Enabled = false;
but its not work.
Posted
Updated 25-May-16 1:40am

1 solution

try this
C#
MenuItem item = NavigationMenu.Items[1].ChildItems[0];
item.Parent.ChildItems.Remove(item);


To remove all the items, we are using reverse loop, since the item is removed from the collection
C#
int count =  NavigationMenu.Items[1].ChildItems.Count;
          for (int i = count-1; i > -1; i--)
          {
              MenuItem item = NavigationMenu.Items[1].ChildItems[i];
              item.Parent.ChildItems.Remove(item);
          }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900