Описание тега checklistbox
CheckBoxList control is a single control that groups a collection of checkboxes which are all rendered through an individual <input type=checkbox></input>
.
With CheckBoxList, you have the option of manually or dynamically creating a group of checkboxes.
To manually create a CheckBoxList:
// in .aspx page
<asp:CheckBoxList 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>
To dynamically create a CheckBoxList:
//in code behind aspx.cs file
//this assumes you have created a CheckBoxList with the ID of CheckBoxDyBind
// specifies the dataset or any object that implements either the IEnumerable or the IListSource interface
CheckBoxDyBind.DataSource = dataset;
// optional property to assign a specific field from the datasource as the text of the checkbox
CheckBoxDyBind.DataTextField ="fullName";
// optional property to assign a specific field from the datasource as the value of the checkbox
CheckBoxDyBind.DataValueField ="personId";
//method to bind the datasource to the control
CheckBoxDyBind.DataBind();
The collection of checkboxes can be referred to with the Items property. To determine which items are checked, iterate through the collection and test the Selected property of each item in the list.
You can also specify how the checkboxes display in the group. The RepeatDirection property specifies if the checkboxes display either horizontally or vertically. The default is vertical. The RepeatLayout property will display the checkboxes either in a HTML table with the RepeatLayout.Table enum or in a span with the RepeatLayout.Flow enum. The default is table.
References