aspnet-devexpress-dot-web-dot-menuitem.md
Gets a collection that contains the submenu items of the current menu item.
Namespace : DevExpress.Web
Assembly : DevExpress.Web.v25.2.dll
NuGet Package : DevExpress.Web
public MenuItemCollection Items { get; }
Public ReadOnly Property Items As MenuItemCollection
| Type | Description |
|---|---|
| MenuItemCollection |
A MenuItemCollection that contains the submenu items of the current menu item.
|
Use the Items property (collection) to access the submenu items of the current menu item, if any. This collection contains only the menu items at the next level. To access menu items further down the menu tree, use the Items property of a subsequent menu item. If the Items property is the null reference ( Nothing in Visual Basic), the current menu item does not have any submenu items.
The Items property can be also used to programmatically manage the submenu 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.
Note that the items of a menu’s root level can be accessed via the ASPxMenuBase.Items property of the menu control.
The code sample below demonstrates how to populate an ASPxMenu control with items manually, in unbound mode. The image below shows the result.
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);
}
}
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If (Not IsPostBack) Then
CreateMenu()
End If
End Sub
'Create Menu initial structure.
Private Sub CreateMenu()
Dim Items() As String = { "Home", "News", "Products", "Client Center" }
For Each ItemText As String In Items
MyMenu.Items.Add(ItemText)
Next ItemText
MyMenu.Items.FindByText("News").Items.Add("Subscriptions")
Dim ProductsItems() As MenuItem = { New MenuItem("Downloads"), New MenuItem("Support"), New MenuItem("Order") }
MyMenu.Items.FindByText("Products").Items.Add(ProductsItems)
End Sub
'Add a new item
Protected Sub btnAddItem_Click(ByVal sender As Object, ByVal e As EventArgs)
If (MyMenu.SelectedItem IsNot Nothing) AndAlso (tbItemName.Text <> "") Then
MyMenu.SelectedItem.Items.Add(tbItemName.Text)
End If
End Sub
<dx:ASPxMenu ID="MyMenu" runat="server" AllowSelectItem="True">
</dx:ASPxMenu>
<dx:ASPxTextBox ID="tbItemName" runat="server" Width="170px">
</dx:ASPxTextBox>
<dx:ASPxButton ID="btnAddItem" runat="server" onclick="btnAddItem_Click" Text="Add Subitem">
</dx:ASPxButton>
See Also