Skip to main content
A newer version of this page is available. .
Tab

ASPxMenuBase.Items Property

Gets a collection that contains menu items of the menu’s root level.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v18.2.dll

Declaration

public MenuItemCollection Items { get; }

Property Value

Type Description
MenuItemCollection

A MenuItemCollection that contains the root level menu items of the current menu control.

Remarks

Use the Items property (collection) to access menu items of the current menu control’s root level, if any. To access menu items further down the menu tree, use the MenuItem.Items property of a subsequent menu item. If the Items property is the null reference (Nothing in Visual Basic), the current menu does not have any menu items.

The Items property can be also used to programmatically manage the root menu items of the current menu item. You can add, insert, remove, retrieve, and modify MenuItem objects from the collection. Any updates to the collection will be automatically reflected in the menu control the next time the page is refreshed.

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);
     }
} 

The following code snippets (auto-collected from DevExpress Examples) contain references to the Items property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also