Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide an ASP.NET Menu Item

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.

like image 349
jwalkerjr Avatar asked Jan 10 '09 04:01

jwalkerjr


3 Answers

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

like image 162
Moiz Tankiwala Avatar answered Nov 19 '22 19:11

Moiz Tankiwala


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

mnuMyMenu.Items.Remove(mnuMyMenu.Items(1))
like image 37
jwalkerjr Avatar answered Nov 19 '22 20:11

jwalkerjr


myMenu.Items(0).ChildItems.Remove(myMenu.Items(0).ChildItems(1))
like image 1
Vijay Gaur Avatar answered Nov 19 '22 19:11

Vijay Gaur