ListItem.Selected プロパティ
アセンブリ: System.Web (system.web.dll 内)

/** @property */ public boolean get_Selected () /** @property */ public void set_Selected (boolean value)
項目が選択されている場合は true。それ以外の場合は false。既定値は false です。

Selected プロパティを使用して、ListItem がそれを格納しているリスト コントロールで現在選択されているかどうかを確認します。通常、このプロパティは、リスト コントロール内の ListItem オブジェクトのコレクションを反復処理するときに、項目が選択されているかどうかを確認するために使用します。

CheckBoxList コントロールの Items コレクションを反復処理するときに、Selected プロパティを使用して選択されているチェック ボックスを確認する方法の例を次に示します。
![]() |
---|
次のコード サンプルはシングルファイル コード モデルを使用しており、分離コード ファイルに直接コピーされた場合は正常に動作しない可能性があります。このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。Web フォームのコード モデルの詳細については、「ASP.NET Web ページのコード モデル」を参照してください。 |
<%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> </head> <body> <script language="VB" runat="server"> Sub Check_Clicked(sender As Object, e As EventArgs) Message.Text = "Selected Item(s):<br><br>" Dim i As Integer For i = 0 To checkboxlist1.Items.Count - 1 If checkboxlist1.Items(i).Selected Then Message.Text = Message.Text & checkboxlist1.Items(i).Text & "<br>" End If Next End Sub </script> <form action="checkboxlist.aspx" method="post" runat="server"> <asp:CheckBoxList id="checkboxlist1" runat="server" AutoPostBack="True" CellPadding="5" CellSpacing="5" RepeatColumns="2" RepeatDirection="Vertical" RepeatLayout="Flow" TextAlign="Right" OnSelectedIndexChanged="Check_Clicked"> <asp:ListItem>Item 1</asp:ListItem> <asp:ListItem>Item 2</asp:ListItem> <asp:ListItem>Item 3</asp:ListItem> <asp:ListItem>Item 4</asp:ListItem> <asp:ListItem>Item 5</asp:ListItem> <asp:ListItem>Item 6</asp:ListItem> </asp:CheckBoxList> <br><br> <asp:label id="Message" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> </head> <body> <script language="C#" runat="server"> void Check_Clicked(Object sender, EventArgs e) { Message.Text="Selected Item(s):" + "<br>" + "<br>"; for (int i=0; i<checkboxlist1.Items.Count; i++) { if (checkboxlist1.Items[i].Selected) Message.Text=Message.Text + checkboxlist1.Items[i].Text + "<br>"; } } </script> <form action="checkboxlist.aspx" method="post" runat="server"> <asp:CheckBoxList id="checkboxlist1" runat="server" AutoPostBack="True" CellPadding="5" CellSpacing="5" RepeatColumns="2" RepeatDirection="Vertical" RepeatLayout="Flow" TextAlign="Right" OnSelectedIndexChanged="Check_Clicked"> <asp:ListItem>Item 1</asp:ListItem> <asp:ListItem>Item 2</asp:ListItem> <asp:ListItem>Item 3</asp:ListItem> <asp:ListItem>Item 4</asp:ListItem> <asp:ListItem>Item 5</asp:ListItem> <asp:ListItem>Item 6</asp:ListItem> </asp:CheckBoxList> <br><br> <asp:label id="Message" runat="server"/> </form> </body> </html>
<%@ Page Language="JScript" AutoEventWireup="True" %> <html> <head> </head> <body> <script language="JSCRIPT" runat="server"> function Check_Clicked(sender : Object, e : EventArgs){ Message.Text = "Selected Item(s):<br><br>" for(var i = 0; i < checkboxlist1.Items.Count; i++){ if(checkboxlist1.Items(i).Selected) Message.Text = Message.Text + checkboxlist1.Items(i).Text + "<br>" } } </script> <form action="checkboxlist.aspx" method="post" runat="server"> <asp:CheckBoxList id="checkboxlist1" runat="server" AutoPostBack="True" CellPadding="5" CellSpacing="5" RepeatColumns="2" RepeatDirection="Vertical" RepeatLayout="Flow" TextAlign="Right" OnSelectedIndexChanged="Check_Clicked"> <asp:ListItem>Item 1</asp:ListItem> <asp:ListItem>Item 2</asp:ListItem> <asp:ListItem>Item 3</asp:ListItem> <asp:ListItem>Item 4</asp:ListItem> <asp:ListItem>Item 5</asp:ListItem> <asp:ListItem>Item 6</asp:ListItem> </asp:CheckBoxList> <br><br> <asp:label id="Message" runat="server"/> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ListItem クラス
ListItem メンバ
System.Web.UI.WebControls 名前空間
ListControl.Items プロパティ
CheckBoxList クラス
ListControl クラス
RadioButtonList
ListBox クラス
DropDownList クラス
CheckBoxList クラス
その他の技術情報
ListBox Web サーバー コントロール
RadioButton Web サーバー コントロールおよび RadioButtonList Web サーバー コントロールの概要
CheckBox Web サーバー コントロールおよび CheckBoxList Web サーバー コントロール
BulletedList Web サーバー コントロール
DropDownList Web サーバー コントロール
Weblioに収録されているすべての辞書からListItem.Selected プロパティを検索する場合は、下記のリンクをクリックしてください。

- ListItem.Selected プロパティのページへのリンク