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.
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
Doh! Ok, I figured it out. The correct syntax is (VB.Net):
mnuMyMenu.Items.Remove(mnuMyMenu.Items(1))
myMenu.Items(0).ChildItems.Remove(myMenu.Items(0).ChildItems(1))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With