This documentation is archived and is not being maintained.

Menu.Items Property

Gets a MenuItemCollection object that contains all menu items in the Menu control.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public MenuItemCollection Items { get; }

Property Value

Type: System.Web.UI.WebControls.MenuItemCollection
A MenuItemCollection that contains all menu items in the Menu control.

Use the Items property (collection) to get a MenuItemCollection object that contains all the menu items in a Menu control. This collection is commonly used to quickly iterate through all the menu items, or to access a specific menu item.

The Items collection can also be used to programmatically manage the menu items. You can add, insert, remove, and retrieve MenuItem collection objects. Any updates to the collection will automatically be reflected in the Menu control after the next round trip to the server.

The following code example demonstrates how to use the Items collection to traverse the menu items in the Menu control.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

  void Page_Load(Object sender, EventArgs e)
    // If the Menu control contains any root nodes, perform a
    // preorder traversal of the tree and display the text of 
    // each node.
    if (NavigationMenu.Items.Count > 0)

      // Iterate through the root menu items in the Items collection.
      foreach (MenuItem item in NavigationMenu.Items)

        // Display the menu items.



      Message.Text = "The Menu control does not have any items.";


  void DisplayChildMenuText(MenuItem item)

    // Display the menu item's text value.
    Message.Text += item.Text + "<br />";

    // Iterate through the child menu items of the parent menu item 
    // passed into this method, and display their values.
    foreach (MenuItem childItem in item.ChildItems)

      // Recursively call the DisplayChildMenuText method to
      // traverse the tree and display all child menu items.




<html xmlns="" >
  <head runat="server">
    <title>Menu Items Example</title>
    <form id="form1" runat="server">

      <h3>Menu Items Example</h3>

      <asp:menu id="NavigationMenu"

          <asp:menuitem text="Home"
            <asp:menuitem text="Music"
              <asp:menuitem text="Classical"
              <asp:menuitem text="Rock"
              <asp:menuitem text="Jazz"
            <asp:menuitem text="Movies"
              <asp:menuitem text="Action"
              <asp:menuitem text="Drama"
              <asp:menuitem text="Musical"



      <asp:label id="Message" 


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.