Hide an ASP.NET Menu Item

2019-02-16 17:58发布

I have an ASP.NET webforms application with a Menu control. How does one hide a particular menu item via code? I've seen a few articles pointing out how to do it with ASP.Net membership/roles-based security, but this particular use case has nothing to do with that. I simply need a way to programmatically remove a menu item from code. Any help would be appreciated.

3条回答
兄弟一词,经得起流年.
2楼-- · 2019-02-16 18:40

Doh! Ok, I figured it out. The correct syntax is (VB.Net):

mnuMyMenu.Items.Remove(mnuMyMenu.Items(1))
查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-02-16 18:45
myMenu.Items(0).ChildItems.Remove(myMenu.Items(0).ChildItems(1))
查看更多
【Aperson】
4楼-- · 2019-02-16 18:54

It would be more straight forward to use

myMenu.Items.RemoveAt(0);

This will remove the first menuitem

myMenu.Items[0].ChildItems.RemoveAt(1);

This will remove the second child of the fist menuitem

myMenu.Items[0].ChildItems[1].ChildItems.RemoveAt(1)

This will remove the second child of the second child of the fist menuitem

查看更多
登录 后发表回答