共用方式為


ListItemCollection 建構函式

定義

初始化 ListItemCollection 類別的新執行個體。

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

範例

下列程式碼範例示範如何建立 ListItemCollection 物件、將專案新增至集合,以及從集合中移除專案。 若要在完整運作的範例中檢視此程式碼,請參閱 WebControl 類別主題。

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

備註

使用此建構函式,使用預設值建立和初始化 類別的新實例 ListItemCollection

適用於