ASP.NET CheckBoxList control

Definition and usage

The CheckBoxList control is used to create a multiple-choice checkbox group.

Each option in a CheckBoxList control is defined by a ListItem element!

Tip:This control supports data binding!

Properties

Properties Description .NET
CellPadding The number of pixels between the border of the table cell and its content. 1.0
CellSpacing The number of pixels between table cells. 1.0
RepeatColumns The number of columns used when displaying the checkbox group. 1.0
RepeatDirection Specify whether the checkbox group is horizontally or vertically repeated. 1.0
RepeatLayout Layout of the checkbox group. 1.0
runat Specify that this control is a server control. It must be set to "server". 1.0
TextAlign Text appears on the side of the checkbox. 1.0

ListControl 标准属性

AppendDataBoundItems, AutoPostBack, CausesValidation, DataTextField,
DataTextFormatString, DataValueField, Items, runat, SelectedIndex, SelectedItem,
SelectedValue, TagKey, Text, ValidationGroup, OnSelectedIndexChanged

ListControl 控件包括列表控件的所有基本功能。继承自此控件的控件包括:CheckBoxList, DropDownList, ListBox 以及 RadioButtonList 控件。

如需完整描述,请访问 ListControl 标准属性.

Web 控件标准属性

AccessKey, Attributes, BackColor, BorderColor, BorderStyle, BorderWidth, 
CssClass, Enabled, Font, EnableTheming, ForeColor, Height, IsEnabled, 
SkinID, Style, TabIndex, ToolTip, Width

如需完整描述,请访问 Web 控件标准属性.

控件标准属性

AppRelativeTemplateSourceDirectory, BindingContainer, ClientID, Controls 
EnableTheming, EnableViewState, ID, NamingContainer, Page, Parent, Site 
TemplateControl, TemplateSourceDirectory, UniqueID, Visible

如需完整描述,请访问控件标准属性.

实例

CheckBoxList
在此例中,我们在 .aspx 文件中声明了一个 CheckBoxList 控件。然后我们为 SelectedIndexChanged 事件创建了一个事件处理程序。这个可选列表包含六个复选框。当用户选中其中之一时,页面会自动将服务器传回,并执行 Check 子例程。该子例程会遍历控件的 Items 集合,并测试每个项目的 Selected 属性。被选中的项目会显示在 Label 控件中。