Home > DeveloperSection > Articles > CheckBoxList Control in ASP.Net

CheckBoxList Control in ASP.Net


ASP.Net ASP.Net 
Ratings:
0 Comment(s)
 6753  View(s)
Rate this:

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:CheckBoxList ID="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 Control in ASP.Net

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:CheckBoxList ID="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:Label ID="Label1" runat="server"></asp:Label>

 

protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)

    {

      

        Label1.Text = CheckBoxList1.SelectedItem.Text;

    }

CheckBoxList Control in ASP.Net

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:CheckBoxList ID="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>

CheckBoxList Control in ASP.Net


Don't want to miss updates? Please click the below button!

Follow MindStick