System.Web.UI.WebControls.MenuItemCollection Class

Represents a collection of menu items in a System.Web.UI.WebControls.Menu control. This class cannot be inherited.

See Also: MenuItemCollection Members


public sealed class MenuItemCollection : ICollection, System.Web.UI.IStateManager


The System.Web.UI.WebControls.MenuItemCollection class is used to store and manage a collection of System.Web.UI.WebControls.MenuItem objects in the System.Web.UI.WebControls.Menu control. The System.Web.UI.WebControls.Menu control uses the System.Web.UI.WebControls.MenuItemCollection class to store its root menu items in the Menu.Items property. This collection is also used for the MenuItem.ChildItems property of a System.Web.UI.WebControls.MenuItem object to store a menu item's submenu items (if any).

The System.Web.UI.WebControls.MenuItemCollection class supports several ways to access the items in the collection:

You can programmatically manage a System.Web.UI.WebControls.MenuItemCollection object by adding and removing System.Web.UI.WebControls.MenuItem objects. To add menu items to the collection, use the MenuItemCollection.Add(MenuItem) or the MenuItemCollection.AddAt(int, MenuItem) method. To remove nodes from the collection, use the MenuItemCollection.Remove(MenuItem), the MenuItemCollection.RemoveAt(int), or the MenuItemCollection.Clear method.


When the System.Web.UI.WebControls.Menu control is bound to a data source, the Menu.Items and MenuItem.ChildItems collections are automatically populated each time binding occurs. Any changes to the collections between bindings will be lost. To retain these changes, either update the data source or manually rebuild the collection each time you bind.

The System.Web.UI.WebControls.MenuItemCollection class contains properties and methods that allow you to retrieve information about the collection itself. To find out how many items are in the collection, use the MenuItemCollection.Count property. If you want to determine whether the collection contains a certain System.Web.UI.WebControls.MenuItem object, use the MenuItemCollection.Contains(MenuItem) method. To get the index of a System.Web.UI.WebControls.MenuItem object in the collection, use the MenuItemCollection.IndexOf(MenuItem) method.


Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions:
Since: .NET 2.0