How to insert multiple Checkboxlist value into database in c#

In this article, we will save many check box values in one data base column. Many times we need to save value multiple values on one column so we can use this below code  and you can also learn how to fetch that values means How to fetch database values in checkbox list in c#

Table Design:-

Source Code:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="chkboxlist.aspx.cs" Inherits="chkboxlist" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">

    <form id="form1" runat="server">
        <fieldset style="width: 150px">
            <legend>Do you have </legend>
            <asp:CheckBoxList ID="CBLID" runat="server" AutoPostBack="True">
                <asp:ListItem>PAN Card</asp:ListItem>
                <asp:ListItem>Student ID</asp:ListItem>
                <asp:ListItem>Voter ID</asp:ListItem>
                <asp:ListItem>Aadhar Card</asp:ListItem>
            <asp:Button ID="BtnSubmit" runat="server" Text="Submit"
                onclick="BtnSubmit_Click" />

Code behind(C#):-

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

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

    protected void BtnSubmit_Click(object sender, EventArgs e)
        String str = "";

        for (int i = 0; i <= CBLID.Items.Count - 1; i++)
            if (CBLID.Items[i].Selected)

                if (str == "")

                    str = CBLID.Items[i].Text;



                    str += "," + CBLID.Items[i].Text;


        SqlConnection con = new SqlConnection("Data Source=NEERAJ-PC;Initial Catalog=CodeSolution;Persist Security Info=True;User ID=sa; password=12345678");
        SqlCommand cmd = new SqlCommand("Insert into reg(IDcard) values('" + str + "')", con);
        Response.Write("Your data Sucessfully saved");


How to insert multiple Checkboxlist value into database in c# How to insert multiple Checkboxlist value into database in c# Reviewed by NEERAJ SRIVASTAVA on 1:08:00 AM Rating: 5


  1. tell about the different between sql code and mysql ???

  2. i am start the develop the website and basically i work on sqldata base but our company use mysql database server so i get trouble to writing code ..

  3. Its good spinnet,very helpfull and easy to implement.

    thank you sooo much..

  4. now same way how to display store value again in checkbox

    1. this code will help you

  5. Neeraj sir i request to you please upload comment post with reply button in c#,sql for website please..........


Powered by Blogger.