System.Web.UI.WebControls.CheckBoxList Class

Creates a multi selection check box group that can be dynamically created by binding the control to a data source.

See Also: CheckBoxList Members


public class CheckBoxList : ListControl, System.Web.UI.INamingContainer, System.Web.UI.IPostBackDataHandler, IRepeatInfoUser


In this topic:


The System.Web.UI.WebControls.CheckBoxList control provides a multi selection check box group that can be dynamically generated with data binding. It contains an ListControl.Items collection with members corresponding to individual items in the list. To determine which items are checked, iterate through the collection and test the ListItem.Selected property of each item in the list.


You can also use multiple System.Web.UI.WebControls.CheckBox controls. The System.Web.UI.WebControls.CheckBoxList control is easier for creating a set of check boxes using data binding, while the individual System.Web.UI.WebControls.CheckBox control gives you greater control over layout.

Specifying List Layout

You can specify the way the list is displayed by using the CheckBoxList.RepeatLayout and CheckBoxList.RepeatDirection properties. For information about layout options, see the System.Web.UI.WebControls.RepeatLayout enumeration.

By default, CheckBoxList.RepeatDirection is set to RepeatDirection.Vertical. Setting this property to RepeatDirection.Horizontal renders the list horizontally. Some CheckBoxList.RepeatLayout settings do not allow horizontal layout. For more information, see the System.Web.UI.WebControls.RepeatLayout enumeration.

Specifying List Items

To specify items that you want to appear in the System.Web.UI.WebControls.CheckBoxList control, place a ListItem element for each entry between the opening and closing tags of the System.Web.UI.WebControls.CheckBoxList control.

The System.Web.UI.WebControls.CheckBoxList control also supports data binding. To bind the control to a data source, first create a data source, such as one of the System.Web.UI.DataSourceControl objects, that contains the items to display in the control. Next, use the System.Web.UI.Control.DataBind method to bind the data source to the System.Web.UI.WebControls.CheckBoxList control. Use the ListControl.DataTextField and ListControl.DataValueField properties to specify which field in the data source to bind to the Text and Value properties of each list item in the control, respectively. The System.Web.UI.WebControls.CheckBoxList control will now display the information from the data source.

To determine the selected items in the System.Web.UI.WebControls.CheckBoxList control, iterate through the ListControl.Items collection and test the ListItem.Selected property of each item in the collection.


This control can be used to display user input, which might include malicious client script. Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. You can use validation controls to verify user input before displaying the input text in a control. ASP.NET provides an input request validation feature to block script and HTML in user input. For more information, see Securing Standard ControlsHow to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings, and Introduction to Validating User Input in ASP.NET Web Pages.


For information about how to configure this control so that it generates markup that conforms to accessibility standards, see Accessibility in Visual Studio 2010 and ASP.NET 4 and ASP.NET Controls and Accessibility.

Declarative Syntax




Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 1.0.5000.0,