Export (0) Print
Expand All

ListItemCollection Constructor

Initializes a new instance of the ListItemCollection class.

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

public ListItemCollection()

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

The following code example demonstrates creating ListItemCollection objects, adding items to the collections, and removing items from the collections. To view this code 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();

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
Show:
© 2015 Microsoft