This documentation is archived and is not being maintained.

ListItemCollection.Count Property

Gets the number of ListItem objects in the collection.

[Visual Basic]
Public Overridable ReadOnly Property Count As Integer  Implements _
   ICollection.Count
[C#]
public virtual int Count {get;}
[C++]
public: __property virtual int get_Count();
[JScript]
public function get Count() : int;

Property Value

The number of ListItem objects in the collection.

Implements

ICollection.Count

Remarks

Use the Count property to determine the number of ListItem objects in the ListItemCollection. The Count property is commonly used when iterating through the collection to determine the upper bound of the collection.

Example

[Visual Basic] 
<!-- To view this code snippet in a fully-working example, see the 
ListItemCollection Class topic. -->

    . . . 
                ' Set the number of rows displayed in the ListBox to be
                ' the number of items in the ListBoxCollection.
                ListBox1.Rows = ListBox1.Items.Count

[C#] 
<!-- To view this code snippet in a fully-working example, see the 
ListItemCollection Class topic. -->

    . . . 
                // Set the number of rows displayed in the ListBox to be
                // the number of items in the ListBoxCollection.
                ListBox1.Rows = ListBox1.Items.Count;

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

ListItemCollection Class | ListItemCollection Members | System.Web.UI.WebControls Namespace | ListItem

Show: