ASP.NET CheckBoxList control

Definition and usage

The CheckBoxList control is used to create a multi-select 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 Pixels between the border of the table cell and its content. 1.0
CellSpacing Pixels between table cells. 1.0
RepeatColumns The number of columns used when displaying the checkbox group. 1.0
RepeatDirection Specifies whether the checkbox group is horizontally or vertically repeated. 1.0
RepeatLayout Layout of checkbox group. 1.0
runat Specifies that the control is a server control. It must be set to "server". 1.0
TextAlign Text appearing on the side of the checkbox. 1.0

ListControl standard properties

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

ListControl controls include all basic functions of list controls. Controls inheriting from this control include: CheckBoxList, DropDownList, ListBox, and RadioButtonList controls.

Aby uzyskać pełną opis, odwiedź ListControl standard properties.

Standardowe właściwości kontrolki Web

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

Aby uzyskać pełną opis, odwiedź Standardowe właściwości kontrolki Web.

Standardowe właściwości kontrolki

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

Aby uzyskać pełną opis, odwiedźStandardowe właściwości kontrolki.

Przykład

CheckBoxList
W tym przykładzie, w pliku .aspx, zadeklarowaliśmy kontrolkę CheckBoxList. Następnie utworzyliśmy obsługiwanie zdarzenia SelectedIndexChanged. Ta opcjonalna lista zawiera sześć pól wyboru. Gdy użytkownik wybierze jedno z nich, strona automatycznie przekaże to do serwera i wykona podprogram Check. Ten podprogram przeszuka kolekcję Items kontrolki i sprawdzi właściwość Selected każdego elementu. Wybrane elementy będą wyświetlane w kontrolce Label.