How to use CheckBoxList Control in ASP.NET

August 27, 2013 , 0 Comments

The CheckBoxList Control

you can use a CheckBoxList control to display a number of check boxes at once as a column of check boxes. The CheckBoxList control exists within the System.Web.UI.WebControls namespace. This control is often useful when you want to bind the data from a datasource to checkboxes . The CheckBoxList control creates multiselection checkbox groups at runtime by binding these controls to a data source.

Use of CheckBoxList Control

  • Where you find multiple options.
  •  In Shoping Site where you find sub category under category 
How to use CheckBoxList Control in ASP.NET

Example of CheckBoxList Control in ASP.NET 

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
        string s = "Your selected books are<br/>";
        foreach (ListItem s1 in CheckBoxList1.Items)
            if (s1.Selected)
                s = s + s1.Text + "<br/>";

        result.Text = s;


    protected void Page_Load(object sender, EventArgs e)

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <div >
Select Your Favorite books:<br />
            <asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True">
                <asp:ListItem>ASP.NET </asp:ListItem>
                <asp:ListItem>WINDOWS FORMS</asp:ListItem>
                <asp:ListItem>JAVA SCRIPT</asp:ListItem>

        <asp:Label ID="result" runat="server"></asp:Label>

How to use CheckBoxList Control in ASP.NET

This example shows that you can choose multiple item in given list. Here foreach loop is running from starting index to ending imdex. When you select ASP.NET book item in the given list then your item will appear on the Label control under the CheckBoxList. If you again select Windows Forms Book in given list , PostBack will occurs and your result will appear on Label Control with previous result.   

Jacob Lefore

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google