A collection of System.Web.UI.WebControls.ListItem objects in a list control. This class cannot be inherited.
See Also: ListItemCollection Members
The System.Web.UI.WebControls.ListItemCollection class represents a collection of System.Web.UI.WebControls.ListItem objects. The System.Web.UI.WebControls.ListItem objects, in turn, represent the items displayed in list controls, such as the System.Web.UI.WebControls.ListBox. To programmatically retrieve System.Web.UI.WebControls.ListItem objects from a list control, use one of following methods:
Use the indexer to get a single System.Web.UI.WebControls.ListItem from the collection, using array notation.
Use the ListItemCollection.CopyTo(Array, int) method to copy the contents of the collection to a Array object, which can then be used to get items from the collection.
Use the ListItemCollection.GetEnumerator method to create a IEnumerator implemented object, which can then be used to get items from the collection.
Use foreach (C#) or For Each (Visual Basic) to iterate through the collection.
The ListItemCollection.Count property specifies the total number of items in the collection, and is commonly used to determine the upper bound of the collection. You can add and remove items from the collection by using the ListItemCollection.Add(string) and ListItemCollection.Remove(string) methods.