CheckBoxList Control in ASP.Net
The Checkbox List control is used to create a multi-selection check box group. The Checkbox List Web server control displays a number of checkboxes at once.
<asp:CheckBoxListID="CheckBoxList1"runat="server">
<asp:ListItem>c</asp:ListItem>
<asp:ListItem>c#</asp:ListItem>
<asp:ListItem>j#</asp:ListItem>
<asp:ListItem>vb</asp:ListItem>
</asp:CheckBoxList>
CheckBoxList Event:
Checkbox List control raises a SelectedIndexChanged event when users select any check box in the list. By default, the event does not cause the form to be posted to the server, although you can specify this option by setting the AutoPostBack property to true.
<asp:CheckBoxListID="CheckBoxList1"runat="server"AutoPostBack="True"
onselectedindexchanged="CheckBoxList1_SelectedIndexChanged">
<asp:ListItem>c</asp:ListItem>
<asp:ListItem>c#</asp:ListItem>
<asp:ListItem>j#</asp:ListItem>
<asp:ListItem>vb</asp:ListItem>
</asp:CheckBoxList>
<asp:LabelID="Label1"runat="server"></asp:Label>
protectedvoid CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text = CheckBoxList1.SelectedItem.Text;
}
When you check the option given in CheckBoxList then SelectedIndexChanged event will fire and selected value will be displayed in the Label
We can change CheckBoxList appearance:
<asp:CheckBoxListID="CheckBoxList1"runat="server"Font-Bold="True"
Font-Italic="True"ForeColor="Red">
<asp:ListItem>c</asp:ListItem>
<asp:ListItem>c#</asp:ListItem>
<asp:ListItem>j#</asp:ListItem>
<asp:ListItem>vb</asp:ListItem>
</asp:CheckBoxList>
Leave Comment