ListItem コンストラクタとは? わかりやすく解説

ListItem コンストラクタ (String, String)

指定したテキスト データと値データ使用してListItem クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

解説解説
使用例使用例
メモメモ

次のコード サンプルはシングルファイル コード モデル使用しており、分離コード ファイル直接コピーされ場合正常に動作しない可能性あります。このコード サンプルは、拡張子.aspx の空のテキスト ファイルコピーする必要がありますWeb フォームコード モデル詳細については、「ASP.NET Web ページコード モデル」を参照してください

<!-- 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"
 %>

<html>
 <head>
 
     <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>
     <p>
     <form 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="C#" AutoEventWireup="True" %>

<html>
 <head>
 
     <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>
     <p>
     <form 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="JScript" AutoEventWireup="True" %>

<html>
 <head>
 
     <script runat="server">
 
         function AddBtn_Click(Sender : Object, e : EventArgs)
 
         {
             if (ListBox1.SelectedIndex > -1) 
             {
                  if (ListBox2.Items.FindByText(ListBox1.SelectedItem.Text)
 == null) 
                 {
                      var Item : ListItem = new
 ListItem(ListBox1.SelectedItem.Text,
                                                         ListBox1.SelectedItem.Value);
                         ListBox2.Items.Add(Item);
                  }
             }
         }
 
         function DelBtn_Click(Sender : Object, e : EventArgs)
 
         {
             if (ListBox2.SelectedIndex > -1) 
             {
                 ListBox2.Items.Remove(ListBox2.SelectedItem);
             }
         }
 
     </script>
 
 </head>
 <body>
 
     <h3>ListItem Example</h3>
     <p>
     <form 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 コンストラクタ (String, String, Boolean)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

指定したテキスト、値、および有効なデータ使用してListItem クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

解説解説
使用例使用例

ListBox コントロールに対して項目を追加および削除する例を次に示します。項目が ListBox1 コントロール選択されたときに、そのテキストの項目が ListBox2 コントロール格納されていない場合は、新しListItem コントロールを同じ値で作成しListBox2 コントロール追加できます。この例では、enabledtrue設定してコンストラクタ呼び出します。enabledfalse設定してコンストラクタ呼び出すと、新しListItem コントロールListBox コントロール表示されません。

メモメモ

次のコード サンプルはシングルファイル コード モデル使用しており、分離コード ファイル直接コピーされ場合正常に動作しない可能性あります。このコード サンプルは、拡張子.aspx の空のテキスト ファイルコピーする必要がありますWeb フォームコード モデル詳細については、「ASP.NET Web ページコード モデル」を参照してください

<%@ Page Language="VB" AutoEventWireup="True"
 %>

<html>
 <head>
 
     <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>
     <p>
     <form 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="C#" AutoEventWireup="True" %>

<html>
 <head>
 
     <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>
     <p>
     <form 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="JScript" AutoEventWireup="True" %>

<html>
 <head>
 
     <script runat="server">
 
         function AddBtn_Click(Sender : Object, e : EventArgs)
 
         {
             if (ListBox1.SelectedIndex > -1) 
             {
                  if (ListBox2.Items.FindByText(ListBox1.SelectedItem.Text)
 == null) 
                 {
                      var Item : ListItem = new
 ListItem(ListBox1.SelectedItem.Text,                        
                        ListBox1.SelectedItem.Value, true);
                         ListBox2.Items.Add(Item);
                  }
             }
         }
 
         function DelBtn_Click(Sender : Object, e : EventArgs)
 
         {
             if (ListBox2.SelectedIndex > -1) 
             {
                 ListBox2.Items.Remove(ListBox2.SelectedItem);
             }
         }
 
     </script>
 
 </head>
 <body>
 
     <h3>ListItem Example</h3>
     <p>
     <form 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 コンストラクタ (String)

指定したテキスト データ使用してListItem クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

解説解説
使用例使用例
メモメモ

次のコード サンプルはシングルファイル コード モデル使用しており、分離コード ファイル直接コピーされ場合正常に動作しない可能性あります。このコード サンプルは、拡張子.aspx の空のテキスト ファイルコピーする必要がありますWeb フォームコード モデル詳細については、「ASP.NET Web ページコード モデル」を参照してください

<!-- 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"
 %>
<html>
 <head>
 
     <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>
     <p>
     <form 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="C#" AutoEventWireup="True" %>

<html>
 <head>
 
     <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>
     <p>
     <form 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="JScript" AutoEventWireup="True" %>

<html>
 <head>
 
     <script language="JScript" runat="server">
 
         function AddBtn_Click(Sender : Object, e : EventArgs)
 
         {
             if (ListBox1.SelectedIndex > -1) 
             {
                  if (ListBox2.Items.FindByText(ListBox1.SelectedItem.Text)
 == null) 
                 {
                      var Item : ListItem = new
 ListItem(ListBox1.SelectedItem.Text);
                     Item.Value = ListBox1.SelectedItem.Value;
                     ListBox2.Items.Add(Item);
                  }
             }
         }
 
         function DelBtn_Click(Sender : Object, e : EventArgs)
 
         {
             if (ListBox2.SelectedIndex > -1) 
             {
                 ListBox2.Items.Remove(ListBox2.SelectedItem);
             }
         }
 
     </script>
 
 </head>
 <body>
 
     <h3>ListItem Example</h3>
     <p>
     <form 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 コンストラクタ ()

ListItem クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

解説解説
使用例使用例
メモメモ

次のコード サンプルはシングルファイル コード モデル使用しており、分離コード ファイル直接コピーされ場合正常に動作しない可能性あります。このコード サンプルは、拡張子.aspx の空のテキスト ファイルコピーする必要がありますWeb フォームコード モデル詳細については、「ASP.NET Web ページコード モデル」を参照してください

<%@ 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.
 -->

<html>
 <head>
 
     <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>
     <p>
     <form 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 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" %>
<html>
 <head>
 
     <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>
     <p>
     <form 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 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="JScript" %>
<html>
 <head>
 
     <script language="JScript" runat="server">
 
         function AddBtn_Click(Sender : Object, e : EventArgs)
 
         {
             if (ListBox1.SelectedIndex > -1) 
             {
                  if (ListBox2.Items.FindByValue(ListBox1.SelectedItem.Text)==null)
 
                 {
                      var Item : ListItem = new
 ListItem();
                      // Text and Value are swapped.
                     Item.Text = ListBox1.SelectedItem.Value;
                     Item.Value = ListBox1.SelectedItem.Text;
                     ListBox2.Items.Add(Item);
                  }
             }
         }
 
         function DelBtn_Click(Sender : Object, e : EventArgs)
 
         {
             if (ListBox2.SelectedIndex > -1) 
             {
                 ListBox2.Items.Remove(ListBox2.SelectedItem);
             }
         }
 
     </script>
 
 </head>
 <body>
 
     <h3>ListItem Example</h3>
     <p>
     <form 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>
          
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ListItem コンストラクタ」の関連用語

ListItem コンストラクタのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ListItem コンストラクタのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS