Category / Section
How to add MenuItem, programmically to the Menu control?
1 min read
Description:
Programmatically, you can add the Menu Item, by defining and adding an object of MenuItem class to the Menu control.
Solution:
To add the Menu Item in a Menu control, you need to do the following things:
- Define properties of the Menu Item object, like Id, Text and ParentId with help of MenuItem class.
- Add the defined item object to the Menu control using the AddItem() method.
Refer the following code example.
C#
MenuItem root=new MenuItem(); root=Menu1.GetItemByID("Root1"); MenuItem newItem=new MenuItem(); newItem.Text="ChildItem"; root.Items.AddItem(newItem);
VB
Private root As MenuItem = New MenuItem() Private root=Menu1.GetItemByID("Root1") Private newItem As MenuItem = New MenuItem() Private newItem.Text="ChildItem" root.Items.AddItem(newItem)