Skip to main content
Tab

MenuItemCollection.Add(String) Method

Adds a new item to the collection and specifies the item’s display text.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.1.dll

NuGet Package: DevExpress.Web

Declaration

public MenuItem Add(
    string text
)

Parameters

Name Type Description
text String

A String value specifying the menu item’s display text. Initializes the menu item’s MenuItem.Text property.

Returns

Type Description
MenuItem

A MenuItem object representing the newly created menu item.

Remarks

Use the Add method to add a new menu item with the specified text to the MenuItemCollection object.

Example

The code sample below demonstrates how to populate an ASPxMenu control with items manually, in unbound mode. The image below shows the result.

ASPxMenu_AddItems

protected void Page_Load(object sender, EventArgs e)
{
     if (!IsPostBack) {
          CreateMenu();
     }
}

//Create Menu initial structure. 
void CreateMenu() {
     string[] Items = { "Home", "News", "Products", "Client Center" };
     foreach (string ItemText in Items) {
          MyMenu.Items.Add(ItemText);
     }
     MyMenu.Items.FindByText("News").Items.Add("Subscriptions");
     MenuItem[] ProductsItems = { 
          new MenuItem("Downloads"), 
          new MenuItem("Support"), 
          new MenuItem("Order") 
     };
     MyMenu.Items.FindByText("Products").Items.Add(ProductsItems);
}

//Add a new item
protected void btnAddItem_Click(object sender, EventArgs e) {
     if ((MyMenu.SelectedItem != null) && (tbItemName.Text != "")) {
          MyMenu.SelectedItem.Items.Add(tbItemName.Text);
     }
} 
See Also