次の方法で共有


ListItemCollection コンストラクタ

ListItemCollection クラスの新しいインスタンスを初期化します。

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

解説

このコンストラクタを使用して、既定値で ListItemCollection クラスの新しいインスタンスを作成し、初期化します。

使用例

 
<!-- 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] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ

参照

ListItemCollection クラス | ListItemCollection メンバ | System.Web.UI.WebControls 名前空間