Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi All,

I have created a menu and based on the rights removing the menu items or child items.

I am able to use the name of main menu item for removing but when i am trying to remove the the child item the string is not accepted and only the integer is accepted.

following is the code successfully working with integer as child item location:

Menu1.FindItem("Masters").ChildItems.Remove(Menu1.FindItem("Masters").ChildItems(0))


Please let me know how i can replace the 0 with name of child item i.e. "TypeMaster"

thanks
Posted
Comments
Sergey Alexandrovich Kryukov 14-Aug-14 7:04am    
Why would you ever need to find anything by name? It give totally non-maintainable code. Don't do it. What is the ultimate purpose of this behavior? And what is the application type? And never use names like "Menu1" (auto-generated).
—SA
atul sharma 5126 14-Aug-14 7:15am    
The purpose of this code is to provide rights to users based on their roles. The list of menu will increase by time and the location also modified hence using the location number will be difficult to maintain.
Sergey Alexandrovich Kryukov 14-Aug-14 8:05am    
How a menu can provide any rights? It does not seem to make any sense. Anyway, you should not rely on searching of objects by names. Changing menu content is way too simple, but you need to do it in a maintainable manner...
—SA
Kschuler 14-Aug-14 9:20am    
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.menuitemcollection.remove(v=vs.110).aspx
atul sharma 5126 14-Aug-14 21:52pm    
Thanks a lot Kschuler. It worked with a little tweaking. The forward slash had to be replaced with backslash:

Menu1.FindItem("Masters").ChildItems.Remove(Menu1.FindItem("Masters/TypeMaster"))

1 solution

SQL
Thanks a lot Kschuler. It worked with a little tweaking. The forward slash had to be replaced with backslash:

Menu1.FindItem("Masters").ChildItems.Remove(Menu1.FindItem("Masters/TypeMaster"))
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900