Articles in this section
Category / Section

How to add a new menu item programmatically?

1 min read

 

Define a Menu control in the ASPX view page with a Root menu item.

ASPX

<syncfusion:Menu ID="Menu1" runat="server">
    <Items>
        <syncfusion:MenuItem ID="Root1" Text="Root 1"></syncfusion:MenuItem>
    </Items>
</syncfusion:Menu>

Refer the below code to programmatically add a menu item under a specified root item using its ID.

C#

//Get the Root Menu Item by GetItemByID method to add the newly created item into it.
Syncfusion.Web.UI.WebControls.Tools.MenuItem root = new Syncfusion.Web.UI.WebControls.Tools.MenuItem();
root = Menu1.GetItemByID("Root1");
//Create the New Menu Item
Syncfusion.Web.UI.WebControls.Tools.MenuItem newItem = new Syncfusion.Web.UI.WebControls.Tools.MenuItem();
newItem.Text = "ChildItem";
root.Items.AddItem(newItem);

 

VB

'Get the Root Menu Item by GetItemByID method to add the newly created item into it.
 Dim root As Syncfusion.Web.UI.WebControls.Tools.MenuItem = New Syncfusion.Web.UI.WebControls.Tools.MenuItem()
 root = Menu1.GetItemByID("Root1")
'Create the New Menu Item
 Dim newItem As Syncfusion.Web.UI.WebControls.Tools.MenuItem = New Syncfusion.Web.UI.WebControls.Tools.MenuItem()
 newItem.Text = "ChildItem"
 root.Items.AddItem(newItem)

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied