如何在ASP.NET Web应用程序中隐藏来自站点主机的子菜单? [英] How can hide the sub menu from site master in ASP.NET web application?
本文介绍了如何在ASP.NET Web应用程序中隐藏来自站点主机的子菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的菜单代码。 员工明智的报告是我在报告菜单下的子菜单。现在我在加载我的网站时如何隐藏这个子菜单?
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: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>
我尝试了什么:
我试过了
NavigationMenu.Items [1] .ChildItems [0] .Enabled = false;
但它不起作用。
What I have tried:
I have tried
NavigationMenu.Items[1].ChildItems[0].Enabled = false;
but its not work.
推荐答案
试试这个
try this
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
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);
}
这篇关于如何在ASP.NET Web应用程序中隐藏来自站点主机的子菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文