The following example code demonstrates how to Display Selected Items from a CheckBoxList Control in ASP.NET.

In fact, a CheckBoxList control available in the ToolBox provides a convenient alternative to display a number of checkboxes on a web page. The following example shows the CheckBoxList control’s usage to display a user’s hobbies. The user can select the hobbies. Furthermore, as the user makes a selection, the Label control shows the selected values. For this purpose, we use the AutoPostBack property. Actually, the AutoPostBack mechanism enables the post back of the page to the server automatically when a certain event occurs.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication31.WebForm2" %>

<!DOCTYPE html>

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
            <br />
            Select Your Hobbies:<br />
&nbsp;<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged">
            <br />
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

The following code shows the code behind file.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication31
    public partial class WebForm2 : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)


        protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
            String str = "";
            foreach(ListItem li in CheckBoxList1.Items)
                    str += li.Text + "  ";
            Label1.Text = "Your hobbies are: " + str;


A Program to Display Selected Items from a CheckBoxList Control in ASP.NET
A Program to Display Selected Items from a CheckBoxList Control in ASP.NET

Further Reading

Examples of Using Code Render Block In ASP.NET

Parameter and ParameterCollection in ADO.NET

Database Manipulation Using DataGrid

Code Render Block in ASP.NET

ASP.NET Practice Exercise