Thursday, 3 March 2016

How to bind CheckBoxList control from DataTable (DataSet) in ASP.Net with C#

In this article, we are going to learn how to bind CheckBoxList control from DataTable(DataSet) c-sharp code in

In Designer File

In designer file, create a CheckBoxList control named as chblstCity.

<div align="center">
  <asp:CheckBoxList ID="chblstCity" runat="server"></asp:CheckBoxList>

Namespaces Used

Include the below Namespace.

using System.Data;

Complete C# Code

Here, we are creating a Datatable dt and adding two columns named as CityId(Int) and CityName(string). Added rows to DataTable and assiging to text field and value field of CheckBoxList.

protected void Page_Load(object sender, EventArgs e)
    if (!IsPostBack)

public void BindCheckBoxList()
    //Creating DataTable 
    DataTable dt = new DataTable();
    //adding Columns to DataTable
    dt.Columns.Add("CityId", typeof(Int32));
    dt.Columns.Add("CityName", typeof(string));
    //Addding data to DataTable         
    dt.Rows.Add(1, "Delhi");
    dt.Rows.Add(2, "Mumbai");
    dt.Rows.Add(3, "Chennai");
    dt.Rows.Add(4, "Kolkata");
    chblstCity.DataSource = dt;
    chblstCity.DataTextField = "CityName";
    //Assigining Text Field
    chblstCity.DataValueField = "CityId";
    //Assigining Value Field


Output will be shown as below.

How to bind checkboxlist control from datatable in


  1. Hi
    Again you have posted a nice article step by step.

    Can you please post a article based on multiple checkbox item in detailsview control for selecting multiple items.

    Thanks in Advance


Email Subscription

Subscribe to our newsletter to get the latest articles directly into your inbox

Blog Archive