ListItem コンストラクター
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
ListItem クラスの新しいインスタンスを初期化します。
オーバーロード
| 名前 | 説明 |
|---|---|
| ListItem() |
ListItem クラスの新しいインスタンスを初期化します。 |
| ListItem(String) |
指定したテキスト データを使用して、 ListItem クラスの新しいインスタンスを初期化します。 |
| ListItem(String, String) |
指定したテキストと値のデータを使用して、 ListItem クラスの新しいインスタンスを初期化します。 |
| ListItem(String, String, Boolean) |
指定したテキスト、値、および有効なデータを使用して、 ListItem クラスの新しいインスタンスを初期化します。 |
ListItem()
ListItem クラスの新しいインスタンスを初期化します。
public:
ListItem();
public ListItem();
Public Sub New ()
例
Note
次のコード サンプルでは、単一ファイルコード モデルを使用します。分離コード ファイルに直接コピーした場合、正しく動作しない可能性があります。 このコード サンプルは、.aspx拡張子が付いている空のテキスト ファイルにコピーする必要があります。 Web フォーム コード モデルの詳細については、「Web フォーム ページ コード モデル ASP.NET」を参照してください。
<!-- The following example demonstrates adding items to and removing items
from ListBox controls. When an item is selected in ListBox1, a new ListBoxItem with
the same value can be created and added to ListBox2, if ListBox2 does not already
contain an item with that value. When the new ListBoxItem is created, it receives
the Value property of the selected item as its Text property, and the Text property
of the selected item as its value property. -->
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ListItem Example</title>
<script runat="server">
void AddBtn_Click(Object Sender, EventArgs e)
{
if (ListBox1.SelectedIndex > -1)
{
if (ListBox2.Items.FindByValue(ListBox1.SelectedItem.Text) == null)
{
ListItem Item = new ListItem();
// Text and Value are swapped.
Item.Text = ListBox1.SelectedItem.Value;
Item.Value = ListBox1.SelectedItem.Text;
ListBox2.Items.Add(Item);
}
}
}
void DelBtn_Click(Object Sender, EventArgs e)
{
if (ListBox2.SelectedIndex > -1)
{
ListBox2.Items.Remove(ListBox2.SelectedItem);
}
}
</script>
</head>
<body>
<h3>ListItem Example</h3>
<form id="form1" runat="server">
<table>
<tr><td>
<asp:ListBox id="ListBox1" Width="100px" runat="server">
<asp:ListItem Value="Value 1">Item 1</asp:ListItem>
<asp:ListItem Value="Value 2">Item 2</asp:ListItem>
<asp:ListItem Value="Value 3">Item 3</asp:ListItem>
<asp:ListItem Value="Value 4">Item 4</asp:ListItem>
<asp:ListItem Value="Value 5" Selected="True">Item 5</asp:ListItem>
<asp:ListItem Value="Value 6">Item 6</asp:ListItem>
</asp:ListBox>
</td><td>
<asp:button Text="--->" OnClick="AddBtn_Click" runat="server" /><br />
<asp:button Text="<---" OnClick="DelBtn_Click" runat="server" />
</td><td>
<asp:ListBox id="ListBox2" Width="100px" runat="server"/>
</td></tr>
</table>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!-- The following example demonstrates adding items to and removing items
from ListBox controls. When an item is selected in ListBox1, a new ListBoxItem with
the same value can be created and added to ListBox2, if ListBox2 does not already
contain an item with that value. When the new ListBoxItem is created, it receives
the Value property of the selected item as its Text property, and the Text property
of the selected item as its value property. -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ListItem Example</title>
<script language="VB" runat="server">
Sub AddBtn_Click(Sender As Object, e As EventArgs)
If ListBox1.SelectedIndex > -1 Then
If ListBox2.Items.FindByValue(ListBox1.SelectedItem.Text) is Nothing Then
Dim Item As ListItem = new ListItem()
'Text and Value are swapped
Item.Text = ListBox1.SelectedItem.Value
Item.Value = ListBox1.SelectedItem.Text
ListBox2.Items.Add(Item)
End If
End If
End Sub
Sub DelBtn_Click(Sender As Object, e As EventArgs)
If ListBox2.SelectedIndex > -1 Then
ListBox2.Items.Remove(ListBox2.SelectedItem)
End If
End Sub
</script>
</head>
<body>
<h3>ListItem Example</h3>
<form id="form1" runat="server">
<table>
<tr><td>
<asp:ListBox id="ListBox1" Width="100px" runat="server">
<asp:ListItem Value="Value 1">Item 1</asp:ListItem>
<asp:ListItem Value="Value 2">Item 2</asp:ListItem>
<asp:ListItem Value="Value 3">Item 3</asp:ListItem>
<asp:ListItem Value="Value 4">Item 4</asp:ListItem>
<asp:ListItem Value="Value 5" Selected="True">Item 5</asp:ListItem>
<asp:ListItem Value="Value 6">Item 6</asp:ListItem>
</asp:ListBox>
</td><td>
<asp:button Text="--->" OnClick="AddBtn_Click" runat="server" /><br />
<asp:button Text="<---" OnClick="DelBtn_Click" runat="server" />
</td><td>
<asp:ListBox id="ListBox2" Width="100px" runat="server"/>
</td></tr>
</table>
</form>
</body>
</html>
注釈
このコンストラクターを使用して、既定値を使用して ListItem クラスの新しいインスタンスを作成および初期化します。
次の表に、 ListItemのインスタンスの初期プロパティ値を示します。
| 財産 | 初期値 |
|---|---|
Text |
null |
Value |
null |
Enabled |
true |
こちらもご覧ください
- ListControl
- RadioButtonList
- ListBox
- DropDownList
- CheckBoxList
- ListBox Web サーバー コントロールの概要
- RadioButton および RadioButtonList Web サーバー コントロールの概要
- BulletedList Web サーバー コントロールの概要
- DropDownList Web サーバー コントロールの概要
適用対象
ListItem(String)
指定したテキスト データを使用して、 ListItem クラスの新しいインスタンスを初期化します。
public:
ListItem(System::String ^ text);
public ListItem(string text);
new System.Web.UI.WebControls.ListItem : string -> System.Web.UI.WebControls.ListItem
Public Sub New (text As String)
パラメーター
例
Note
次のコード サンプルでは、単一ファイルコード モデルを使用します。分離コード ファイルに直接コピーした場合、正しく動作しない可能性があります。 このコード サンプルは、.aspx拡張子が付いている空のテキスト ファイルにコピーする必要があります。 Web フォーム コード モデルの詳細については、「Web フォーム ページ コード モデル ASP.NET」を参照してください。
<!-- The following example demonstrates adding items to and removing items
from ListBox controls. When an item is selected in ListBox1, a new ListBoxItem with
the same value can be created and added to ListBox2, if ListBox2 does not already
contain an item with that text. -->
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ListItem Example</title>
<script runat="server">
void AddBtn_Click(Object Sender, EventArgs e)
{
if (ListBox1.SelectedIndex > -1)
{
if (ListBox2.Items.FindByText(ListBox1.SelectedItem.Text) == null)
{
ListItem Item = new ListItem(ListBox1.SelectedItem.Text);
Item.Value = ListBox1.SelectedItem.Value;
ListBox2.Items.Add(Item);
}
}
}
void DelBtn_Click(Object Sender, EventArgs e)
{
if (ListBox2.SelectedIndex > -1)
{
ListBox2.Items.Remove(ListBox2.SelectedItem);
}
}
</script>
</head>
<body>
<h3>ListItem Example</h3>
<form id="form1" runat="server">
<table>
<tr><td>
<asp:ListBox id="ListBox1" Width="100px" runat="server">
<asp:ListItem Value="Value 1">Item 1</asp:ListItem>
<asp:ListItem Value="Value 2">Item 2</asp:ListItem>
<asp:ListItem Value="Value 3">Item 3</asp:ListItem>
<asp:ListItem Value="Value 4">Item 4</asp:ListItem>
<asp:ListItem Value="Value 5" Selected="True">Item 5</asp:ListItem>
<asp:ListItem Value="Value 6">Item 6</asp:ListItem>
</asp:ListBox>
</td><td>
<asp:button Text="--->" OnClick="AddBtn_Click" runat="server" /><br />
<asp:button Text="<---" OnClick="DelBtn_Click" runat="server" />
</td><td>
<asp:ListBox id="ListBox2" Width="100px" runat="server"/>
</td></tr>
</table>
</form>
</body>
</html>
<!-- The following example demonstrates adding items to and removing items
from ListBox controls. When an item is selected in ListBox1, a new ListBoxItem with
the same value can be created and added to ListBox2, if ListBox2 does not already
contain an item with that text. -->
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ListItem Example</title>
<script runat="server">
Sub AddBtn_Click(Sender As Object, e As EventArgs)
If ListBox1.SelectedIndex > -1 Then
If ListBox2.Items.FindByText(ListBox1.SelectedItem.Text) is Nothing Then
Dim Item As ListItem = new ListItem(ListBox1.SelectedItem.Text)
Item.Value = ListBox1.SelectedItem.Value
ListBox2.Items.Add(Item)
End If
End If
End Sub
Sub DelBtn_Click(Sender As Object, e As EventArgs)
If ListBox2.SelectedIndex > -1 Then
ListBox2.Items.Remove(ListBox2.SelectedItem)
End If
End Sub
</script>
</head>
<body>
<h3>ListItem Example</h3>
<form id="form1" runat="server">
<table>
<tr><td>
<asp:ListBox id="ListBox1" Width="100px" runat="server">
<asp:ListItem Value="Value 1">Item 1</asp:ListItem>
<asp:ListItem Value="Value 2">Item 2</asp:ListItem>
<asp:ListItem Value="Value 3">Item 3</asp:ListItem>
<asp:ListItem Value="Value 4">Item 4</asp:ListItem>
<asp:ListItem Value="Value 5" Selected="True">Item 5</asp:ListItem>
<asp:ListItem Value="Value 6">Item 6</asp:ListItem>
</asp:ListBox>
</td><td>
<asp:button Text="--->" OnClick="AddBtn_Click" runat="server" /><br />
<asp:button Text="<---" OnClick="DelBtn_Click" runat="server" />
</td><td>
<asp:ListBox id="ListBox2" Width="100px" runat="server"/>
</td></tr>
</table>
</form>
</body>
</html>
注釈
このコンストラクターを使用して、指定したテキストを使用して、 ListItem クラスの新しいインスタンスを作成および初期化します。
次の表に、 ListItemのインスタンスの初期プロパティ値を示します。
| 財産 | 初期値 |
|---|---|
Text |
text パラメーターの値。 |
Value |
null |
Enabled |
true |
こちらもご覧ください
- ListControl
- RadioButtonList
- ListBox
- DropDownList
- CheckBoxList
- ListBox Web サーバー コントロールの概要
- RadioButton および RadioButtonList Web サーバー コントロールの概要
- BulletedList Web サーバー コントロールの概要
- DropDownList Web サーバー コントロールの概要
適用対象
ListItem(String, String)
指定したテキストと値のデータを使用して、 ListItem クラスの新しいインスタンスを初期化します。
public:
ListItem(System::String ^ text, System::String ^ value);
public ListItem(string text, string value);
new System.Web.UI.WebControls.ListItem : string * string -> System.Web.UI.WebControls.ListItem
Public Sub New (text As String, value As String)
パラメーター
例
Note
次のコード サンプルでは、単一ファイルコード モデルを使用します。分離コード ファイルに直接コピーした場合、正しく動作しない可能性があります。 このコード サンプルは、.aspx拡張子が付いている空のテキスト ファイルにコピーする必要があります。 Web フォーム コード モデルの詳細については、「Web フォーム ページ コード モデル ASP.NET」を参照してください。
<!-- The following example demonstrates adding items to and removing items
from ListBox controls. When an item is selected in ListBox1, a new ListBoxItem with
the same value can be created and added to ListBox2, if ListBox2 does not already
contain an item with that text. -->
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ListItem Example</title>
<script runat="server">
void AddBtn_Click(Object Sender, EventArgs e)
{
if (ListBox1.SelectedIndex > -1)
{
if (ListBox2.Items.FindByText(ListBox1.SelectedItem.Text) == null)
{
ListItem Item = new ListItem(ListBox1.SelectedItem.Text,
ListBox1.SelectedItem.Value);
ListBox2.Items.Add(Item);
}
}
}
void DelBtn_Click(Object Sender, EventArgs e)
{
if (ListBox2.SelectedIndex > -1)
{
ListBox2.Items.Remove(ListBox2.SelectedItem);
}
}
</script>
</head>
<body>
<h3>ListItem Example</h3>
<form id="form1" runat="server">
<table>
<tr><td>
<asp:ListBox id="ListBox1" Width="100px" runat="server">
<asp:ListItem Value="Value 1">Item 1</asp:ListItem>
<asp:ListItem Value="Value 2">Item 2</asp:ListItem>
<asp:ListItem Value="Value 3">Item 3</asp:ListItem>
<asp:ListItem Value="Value 4">Item 4</asp:ListItem>
<asp:ListItem Value="Value 5" Selected="True">Item 5</asp:ListItem>
<asp:ListItem Value="Value 6">Item 6</asp:ListItem>
</asp:ListBox>
</td><td>
<asp:button Text="--->" OnClick="AddBtn_Click" runat="server" /><br />
<asp:button Text="<---" OnClick="DelBtn_Click" runat="server" />
</td><td>
<asp:ListBox id="ListBox2" Width="100px" runat="server"/>
</td></tr>
</table>
</form>
</body>
</html>
<!-- The following example demonstrates adding items to and removing items
from ListBox controls. When an item is selected in ListBox1, a new ListBoxItem with
the same value can be created and added to ListBox2, if ListBox2 does not already
contain an item with that text. -->
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ListItem Example</title>
<script runat="server">
Sub AddBtn_Click(Sender As Object, e As EventArgs)
If ListBox1.SelectedIndex > -1 Then
If ListBox2.Items.FindByText(ListBox1.SelectedItem.Text) is Nothing Then
Dim Item As ListItem = new ListItem(ListBox1.SelectedItem.Text, _
ListBox1.SelectedItem.Value)
ListBox2.Items.Add(Item)
End If
End If
End Sub
Sub DelBtn_Click(Sender As Object, e As EventArgs)
If ListBox2.SelectedIndex > -1 Then
ListBox2.Items.Remove(ListBox2.SelectedItem)
End If
End Sub
</script>
</head>
<body>
<h3>ListItem Example</h3>
<form id="form1" runat="server">
<table>
<tr><td>
<asp:ListBox id="ListBox1" Width="100px" runat="server">
<asp:ListItem Value="Value 1">Item 1</asp:ListItem>
<asp:ListItem Value="Value 2">Item 2</asp:ListItem>
<asp:ListItem Value="Value 3">Item 3</asp:ListItem>
<asp:ListItem Value="Value 4">Item 4</asp:ListItem>
<asp:ListItem Value="Value 5" Selected="True">Item 5</asp:ListItem>
<asp:ListItem Value="Value 6">Item 6</asp:ListItem>
</asp:ListBox>
</td><td>
<asp:button Text="--->" OnClick="AddBtn_Click" runat="server" /><br />
<asp:button Text="<---" OnClick="DelBtn_Click" runat="server" />
</td><td>
<asp:ListBox id="ListBox2" Width="100px" runat="server"/>
</td></tr>
</table>
</form>
</body>
</html>
注釈
このコンストラクターを使用して、指定したテキストと値を使用して、 ListItem クラスの新しいインスタンスを作成および初期化します。
次の表に、 ListItemのインスタンスの初期プロパティ値を示します。
| 財産 | 初期値 |
|---|---|
Text |
text パラメーターの値。 |
Value |
value パラメーターの値。 |
Enabled |
true |
こちらもご覧ください
- ListControl
- RadioButtonList
- ListBox
- DropDownList
- CheckBoxList
- ListBox Web サーバー コントロールの概要
- RadioButton および RadioButtonList Web サーバー コントロールの概要
- BulletedList Web サーバー コントロールの概要
- DropDownList Web サーバー コントロールの概要
適用対象
ListItem(String, String, Boolean)
指定したテキスト、値、および有効なデータを使用して、 ListItem クラスの新しいインスタンスを初期化します。
public:
ListItem(System::String ^ text, System::String ^ value, bool enabled);
public ListItem(string text, string value, bool enabled);
new System.Web.UI.WebControls.ListItem : string * string * bool -> System.Web.UI.WebControls.ListItem
Public Sub New (text As String, value As String, enabled As Boolean)
パラメーター
例
次の例では、 ListBox コントロールへの項目の追加と削除を示します。
ListBox1 コントロールで項目を選択すると、同じ値を持つ新しいListItem コントロールを作成し、ListBox2 コントロールに追加できます (ListBox2 コントロールにそのテキストを含む項目がまだ含まれていない場合)。 この例では、コンストラクターは enabledtrue に設定して呼び出されます。
enabledが false に設定された状態で呼び出された場合、新しいListItem コントロールはListBox コントロールに表示されません。
Note
次のコード サンプルでは、単一ファイルコード モデルを使用します。分離コード ファイルに直接コピーした場合、正しく動作しない可能性があります。 このコード サンプルは、.aspx拡張子が付いている空のテキスト ファイルにコピーする必要があります。 Web フォーム コード モデルの詳細については、「Web フォーム ページ コード モデル ASP.NET」を参照してください。
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ListItem Example</title>
<script runat="server">
void AddBtn_Click(Object Sender, EventArgs e)
{
if (ListBox1.SelectedIndex > -1)
{
if (ListBox2.Items.FindByText(ListBox1.SelectedItem.Text) == null)
{
ListItem Item = new ListItem(ListBox1.SelectedItem.Text,
ListBox1.SelectedItem.Value, true);
ListBox2.Items.Add(Item);
}
}
}
void DelBtn_Click(Object Sender, EventArgs e)
{
if (ListBox2.SelectedIndex > -1)
{
ListBox2.Items.Remove(ListBox2.SelectedItem);
}
}
</script>
</head>
<body>
<h3>ListItem Example</h3>
<form id="form1" runat="server">
<table>
<tr><td>
<asp:ListBox id="ListBox1" Width="100px" runat="server">
<asp:ListItem Value="Value 1">Item 1</asp:ListItem>
<asp:ListItem Value="Value 2">Item 2</asp:ListItem>
<asp:ListItem Value="Value 3">Item 3</asp:ListItem>
<asp:ListItem Value="Value 4">Item 4</asp:ListItem>
<asp:ListItem Value="Value 5" Selected="True">Item 5</asp:ListItem>
<asp:ListItem Value="Value 6">Item 6</asp:ListItem>
</asp:ListBox>
</td><td>
<asp:button Text="--->" OnClick="AddBtn_Click" runat="server" /><br />
<asp:button Text="<---" OnClick="DelBtn_Click" runat="server" />
</td><td>
<asp:ListBox id="ListBox2" Width="100px" runat="server"/>
</td></tr>
</table>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ListItem Example</title>
<script runat="server">
Sub AddBtn_Click(Sender As Object, e As EventArgs)
If ListBox1.SelectedIndex > -1 Then
If ListBox2.Items.FindByText(ListBox1.SelectedItem.Text) is Nothing Then
Dim Item As ListItem = New ListItem(ListBox1.SelectedItem.Text, _
ListBox1.SelectedItem.Value, True)
ListBox2.Items.Add(Item)
End If
End If
End Sub
Sub DelBtn_Click(Sender As Object, e As EventArgs)
If ListBox2.SelectedIndex > -1 Then
ListBox2.Items.Remove(ListBox2.SelectedItem)
End If
End Sub
</script>
</head>
<body>
<h3>ListItem Example</h3>
<form id="form1" runat="server">
<table>
<tr><td>
<asp:ListBox id="ListBox1" Width="100px" runat="server">
<asp:ListItem Value="Value 1">Item 1</asp:ListItem>
<asp:ListItem Value="Value 2">Item 2</asp:ListItem>
<asp:ListItem Value="Value 3">Item 3</asp:ListItem>
<asp:ListItem Value="Value 4">Item 4</asp:ListItem>
<asp:ListItem Value="Value 5" Selected="True">Item 5</asp:ListItem>
<asp:ListItem Value="Value 6">Item 6</asp:ListItem>
</asp:ListBox>
</td><td>
<asp:button Text="--->" OnClick="AddBtn_Click" runat="server" /><br />
<asp:button Text="<---" OnClick="DelBtn_Click" runat="server" />
</td><td>
<asp:ListBox id="ListBox2" Width="100px" runat="server"/>
</td></tr>
</table>
</form>
</body>
</html>
注釈
次の表に、 ListItemのインスタンスの初期プロパティ値を示します。
| 財産 | 初期値 |
|---|---|
Text |
text パラメーターの値。 |
Value |
value パラメーターの値。 |
Enabled |
enabled パラメーターの値。 |
こちらもご覧ください
- ListControl
- RadioButtonList
- ListBox
- DropDownList
- CheckBoxList
- ListBox Web サーバー コントロールの概要
- RadioButton および RadioButtonList Web サーバー コントロールの概要
- BulletedList Web サーバー コントロールの概要
- DropDownList Web サーバー コントロールの概要