This documentation is archived and is not being maintained.

MenuItem.ChildItems Property

Gets a MenuItemCollection object that contains the submenu items of the current menu item.

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

public MenuItemCollection ChildItems { get; }

Property Value

Type: System.Web.UI.WebControls.MenuItemCollection
A MenuItemCollection that contains the submenu items of the current menu item. The default is null, which indicates that this menu item does not contain any submenu items.

Use the ChildItems 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 ChildItems property of a subsequent menu item. If the ChildItems property is null, the current menu does not have any submenu items.

The ChildItems property can also be 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 automatically be reflected in the Menu control the next time the page is refreshed.

The following example demonstrates how to use the ChildItems property to traverse the menu items in a 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" 


Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0