Support us .Net Basics C# SQL ASP.NET Aarvi MVC Slides C# Programs Subscribe Download

ASP.NET CheckBoxList and ListBox real time example - Part 26

Suggested Videos
Part 23 - checkboxlist control
Part 24 - checkboxlist, select or deselect all list items
Part 25 - ASP.NET ListBox control

In this video we will discuss about a simple real time example using checkboxlist and listbox.

Copy and Paste the following HTML on the ASPX page
<asp:CheckBoxList ID="CheckBoxList1" runat="server" 
    RepeatDirection="Horizontal" AutoPostBack="True" 
    <asp:ListItem Text="Diploma" Value="1"></asp:ListItem>
    <asp:ListItem Text="Graduate" Value="2"></asp:ListItem>
    <asp:ListItem Text="Post Graduate" Value="3"></asp:ListItem>
    <asp:ListItem Text="Doctrate" Value="4"></asp:ListItem>
<br />
<asp:ListBox ID="ListBox1" runat="server" Height="78px" Width="127px">
<br /><br />
<asp:Label ID="lblMessage" runat="server" Font-Bold="true"></asp:Label>

Copy and Paste the following code in the code behind page
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
    // Everytime the selection changes, clear the items in the listbox
    // Loop thru each litemitem in the checkboxlist
    foreach (ListItem li in CheckBoxList1.Items)
        // If the listitem is selected
        if (li.Selected)
            // Add the listitem text to the listbox

            // Add the lisitem as an object. This ensures the listitem is 
            // selected in the listbox. For this to work, listbox, 
            // SelectionMode must be set to Multiple. The SelectionMode
            // Property can be set in the HTML source also.
            // ListBox1.SelectionMode = ListSelectionMode.Multiple
            // ListBox1.Items.Add(li);
    // If nothing is selected from the checkboxlist
    if (CheckBoxList1.SelectedIndex == -1)
        // Set the label ForeColor to Red
        lblMessage.ForeColor = System.Drawing.Color.Red;
    // If atleast one listitem is selected
        // Set the label forecolor to black
        lblMessage.ForeColor = System.Drawing.Color.Black;
    // Display the total number of items selected from the checkboxlist
    lblMessage.Text = ListBox1.Items.Count.ToString() + " item(s) selected";


  1. Dear Sir,
    I'm a big fan of your tutorials and constantly gaining knowledge through your videos. A big Thanks for you

    Sir I have a little problem as I am an IT student
    and doing project on shoping cart system but
    stuck in Search filteration module by multiple checkboxes
    Sir please give me Idea how to do Filteration from multiple checkboxes and bind data into gridview in ASP.NET
    Thanks in Advance Sir

  2. i am unable to solve for quite a while now- i want to show the values of a table that are in relation with the checkbox values that comes from another table. so basically, for example, there are two types in one table "consultant" and "supplier". now in another table there services, "hvac" and "generator" under "consultant", and services, "bulb" and "fan" under "supplier". how can when "consultant" checkbox is checked it will only show "hvac" and "generator", and same thing for "supplier"?

  3. Very Good Evening Sir,

    I would like to thank you for sharing your knowledge and making people to learn in very simple way with those materials.

    I am in need of some coding help sir, How can i reach you and would like to know online classes fee structure for and MVC.

    Subhiksh Kulkarni


It would be great if you can help share these free resources