ListItemCollection Class

A collection of ListItem objects in a list control. This class cannot be inherited.

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

public ref class ListItemCollection sealed : IList, ICollection, IEnumerable, 
	IStateManager
public final class ListItemCollection implements IList, ICollection, 
	IEnumerable, IStateManager
public final class ListItemCollection implements IList, ICollection, 
	IEnumerable, IStateManager

The ListItemCollection class represents a collection of ListItem objects. The ListItem objects, in turn, represent the items displayed in list controls, such as the ListBox. To programmatically retrieve ListItem objects from a list control, use one of following methods:

  • Use the indexer to get a single ListItem from the collection, using array notation.

  • Use the CopyTo method to copy the contents of the collection to a System.Array object, which can then be used to get items from the collection.

  • Use the GetEnumerator method to create a System.Collections.IEnumerator implemented object, which can then be used to get items from the collection.

  • Use foreach (C#) or For Each (Visual Basic) to iterate throught the collection.

The 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 Add and Remove methods.

The following code example demonstrates creating ListItemCollection objects, adding items to the collections, and removing items from the collections. In the example, the ListItemCollection named listBoxData is used as the data source for a ListBox control called ListBox1, and the ListItemCollection called ddBoxData is used as the data source for a DropDownList control called DropDownList1.

No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.

System.Object
  System.Web.UI.WebControls.ListItemCollection

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show: