views:

2791

answers:

4

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.

+1  A: 

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

mnuMyMenu.Items.Remove(mnuMyMenu.Items(1))
jwalkerjr
You know you can accept your own answers?
Kev
A: 

also, myMenu.Items(0).ChildItems.Remove(myMenu.Items(0).ChildItems(1))

Vijay Gaur
A: 

Child Menu can't be removed, you have to set child menu text to "" and set it disable. Example : mnuShopping.Items(0).ChildItems.Item(3).Text = "" mnuShopping.Items(0).ChildItems.Item(3).Enabled = False

CNP Thailand.