MenuItemCollection Class
Assembly: System.Web (in system.web.dll)
The MenuItemCollection class is used to store and manage a collection of MenuItem objects in the Menu control. The Menu control uses the MenuItemCollection class to store its root menu items in the Items property. This collection is also used for the ChildItems property of a MenuItem object to store a menu item's submenu items (if any).
The MenuItemCollection class supports several ways to access the items in the collection:
-
Use the Item indexer to directly retrieve a MenuItem object at a specific zero-based index.
-
Use the GetEnumerator method to create an enumerator that can be used to iterate through the collection.
-
Use the CopyTo method to copy the contents of the collection into an array.
You can programmatically manage a MenuItemCollection object by adding and removing MenuItem objects. To add menu items to the collection, use the Add or the AddAt method. To remove nodes from the collection, use the Remove, the RemoveAt, or the Clear method.
Note: |
|---|
| When the Menu control is bound to a data source, the Items and 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 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 Count property. If you want to determine whether the collection contains a certain MenuItem object, use the Contains method. To get the index of a MenuItem object in the collection, use the IndexOf method.
| Topic | Location |
|---|---|
| Walkthrough: Displaying a Menu on Web Pages | Building ASP .NET Web Applications in Visual Studio |
| Walkthrough: Controlling ASP.NET Menus Programmatically | Building ASP .NET Web Applications in Visual Studio |
- AspNetHostingPermission for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
Note: