ListItemCollection Konstruktor

Definition

Initialisiert eine neue Instanz der ListItemCollection-Klasse.

public:
 ListItemCollection();
public ListItemCollection ();
Public Sub New ()

Beispiele

Im folgenden Codebeispiel wird das Erstellen von ListItemCollection Objekten, das Hinzufügen von Elementen zu den Auflistungen und das Entfernen von Elementen aus den Auflistungen veranschaulicht. Informationen zum Anzeigen dieses Codes in einem vollständig funktionierenden Beispiel finden Sie im WebControl Klassenthema.

// 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();
' 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()

Hinweise

Verwenden Sie diesen Konstruktor, um eine neue Instanz der ListItemCollection -Klasse mithilfe von Standardwerten zu erstellen und zu initialisieren.

Gilt für: