This documentation is archived and is not being maintained.

ListItemCollection Constructor

Initializes a new instance of the ListItemCollection class.

[Visual Basic]
Public Sub New()
[C#]
public ListItemCollection();
[C++]
public: ListItemCollection();
[JScript]
public function ListItemCollection();

Remarks

Use this constructor to create and initialize a new instance of the ListItemCollection class using default values.

Example

[Visual Basic] 
<!-- This example demonstrates creating ListItemCollection objects, 
adding items to the collections, and removing items from the collections. -->
    . . . 
<!-- To view this code snippet in a fully-working example, see the 
WebControl Class topic. -->

    . . . 
                    ' Create a new ListItemCollection.
                    Dim listBoxData As New ListItemCollection()
                    ' Add items to the collection.
                    listBoxData.Add(New ListItem("apples"))
                    listBoxData.Add(New ListItem("bananas"))
                    listBoxData.Add(New ListItem("cherries"))
                    listBoxData.Add("grapes")
                    listBoxData.Add("mangos")
                    listBoxData.Add("oranges")
                    ' Set the ListItemCollection as the data source for ListBox1.
                    ListBox1.DataSource = listBoxData
                    ListBox1.DataBind()

[C#] 
<!-- This example demonstrates creating ListItemCollection objects, 
adding items to the collections, and removing items from the collections. -->
    . . . 
<!-- To view this code snippet in a fully-working example, see the 
WebControl Class topic. -->

    . . . 
                    // Create a new ListItemCollection.
                    ListItemCollection listBoxData = new ListItemCollection();
                    // Add items to the collection.
                    listBoxData.Add(new ListItem("apples"));
                    listBoxData.Add(new ListItem("bananas"));
                    listBoxData.Add(new ListItem("cherries"));
                    listBoxData.Add("grapes");
                    listBoxData.Add("mangos");
                    listBoxData.Add("oranges");
                    // Set the ListItemCollection as the data source for ListBox1.
                    ListBox1.DataSource = listBoxData;
                    ListBox1.DataBind();

[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

Show: