CheckBoxList クラス
アセンブリ: System.Web (system.web.dll 内)

Public Class CheckBoxList Inherits ListControl Implements IRepeatInfoUser, INamingContainer, IPostBackDataHandler
public ref class CheckBoxList : public ListControl, IRepeatInfoUser, INamingContainer, IPostBackDataHandler

CheckBoxList コントロールを使用すると、データ連結によって動的に生成できる複数選択チェック ボックス グループを利用できます。これには、リストのそれぞれの項目に対応するメンバを持つ Items コレクションが含まれます。どの項目がチェックされているかを判断するには、そのコレクションを反復処理してリストの各項目の Selected プロパティをテストします。
リストの表示方法は RepeatLayout プロパティおよび RepeatDirection プロパティで指定できます。RepeatLayout を RepeatLayout.Table (既定の設定) に設定した場合、リストはテーブル内に表示されます。RepeatLayout.Flow に設定した場合、リストはテーブル構造なしで表示されます。既定では、RepeatDirection は RepeatDirection.Vertical に設定されます。このプロパティを RepeatDirection.Horizontal に設定すると、リストは水平に表示されます。
CheckBoxList コントロールには、便利なデータ連結機能が用意されています。それぞれの CheckBox コントロールには強力なレイアウト制御機能が用意されています。
![]() |
---|
このコントロールは、ユーザー入力を表示するために使用できます。ユーザー入力には悪意のあるクライアント スクリプトが含まれている可能性があります。アプリケーションに表示する前に、クライアントから送信された実行スクリプト、SQL ステートメントなどのコードの情報はすべて検証してください。入力テキストをコントロールに表示する前に、検証コントロールを使用してユーザー入力を検証できます。ASP.NET には入力要求の検証機能があり、ユーザー入力の中のスクリプトおよび HTML をブロックできます。詳細については、「標準コントロールのセキュリティ保護」、「方法 : HTML エンコーディングを文字列に適用して Web アプリケーションをスクリプトによる攻略から保護する」、および「ASP.NET Web ページにおけるユーザー入力の検証」を参照してください。 |
ユーザー補助
このコントロールに既定でレンダリングされるマークアップは、Web Content Accessibility Guidelines (WCAG) 1.0 の優先度 1 ガイドラインなどのユーザー補助に関する標準に適合しない可能性があります。このコントロールのユーザー補助サポートの詳細については、「ASP.NET コントロールとユーザー補助」を参照してください。

Web ページに CheckBoxList コントロールを作成する方法のコード例を次に示します。
![]() |
---|
次のコード サンプルはシングルファイル コード モデルを使用しており、分離コード ファイルに直接コピーされた場合は正常に動作しない可能性があります。このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。Web フォームのコード モデルの詳細については、「ASP.NET Web ページのコード モデル」を参照してください。 |
<%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script runat="server"> Sub Check_Clicked(sender as Object, e As EventArgs) Message.Text = "Selected Item(s):<br><br>" ' Iterate through the Items collection of the CheckBoxList ' control and display the selected items. Dim i As Integer For i=0 To checkboxlist1.Items.Count - 1 If checkboxlist1.Items(i).Selected Then Message.Text &= checkboxlist1.Items(i).Text & "<br>" End If Next End Sub </script> </head> <body> <form runat="server"> <h3> CheckBoxList Example </h3> Select items from the CheckBoxList. <br><br> <asp:CheckBoxList id="checkboxlist1" AutoPostBack="True" CellPadding="5" CellSpacing="5" RepeatColumns="2" RepeatDirection="Vertical" RepeatLayout="Flow" TextAlign="Right" OnSelectedIndexChanged="Check_Clicked" runat="server"> <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> <script runat="server"> void Check_Clicked(Object sender, EventArgs e) { Message.Text = "Selected Item(s):<br><br>"; // Iterate through the Items collection of the CheckBoxList // control and display the selected items. for (int i=0; i<checkboxlist1.Items.Count; i++) { if (checkboxlist1.Items[i].Selected) { Message.Text += checkboxlist1.Items[i].Text + "<br>"; } } } </script> </head> <body> <form runat="server"> <h3> CheckBoxList Example </h3> Select items from the CheckBoxList. <br><br> <asp:CheckBoxList id="checkboxlist1" AutoPostBack="True" CellPadding="5" CellSpacing="5" RepeatColumns="2" RepeatDirection="Vertical" RepeatLayout="Flow" TextAlign="Right" OnSelectedIndexChanged="Check_Clicked" runat="server"> <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>


System.Web.UI.Control
System.Web.UI.WebControls.WebControl
System.Web.UI.WebControls.BaseDataBoundControl
System.Web.UI.WebControls.DataBoundControl
System.Web.UI.WebControls.ListControl
System.Web.UI.WebControls.CheckBoxList


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- CheckBoxList クラスのページへのリンク