Click here to Skip to main content
15,569,840 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to store multiple value of checkboxlist

here is my checkbox list

<asp:CheckBoxList ID="chkMaritalStatus" runat="server" CssClass="rb" RepeatDirection="Horizontal">
<asp:ListItem>Awaiting divorce</asp:ListItem>

and i want to multiple items in my database how can i do that?
Updated 10-Jul-12 20:30pm
vangapally Naveen Kumar 11-Jul-12 1:15am    
Can You elaborate more.....

Here,chklstSubject is checkbox name and we are store selected items in sub.

          String sub="";
          for (int i = 0; i < chklstSubject.Items.Count; i++)
                if (chklstSubject.Items[i].Selected)
                    sub += chklstSubject.Items[i].Value + ",";
            sub = sub.TrimEnd(',');

insert sub into query,

String qr="insert into tabl1 values('"+sub+"')";
Share this answer
Assuming that your database contains single column called MaritalStatus which can accept comma separated values, see if below code helps you:

string status= string.Empty; 
        foreach (ListItem item in this.CheckBoxList1.Items) 
            if (item.Selected) 
                status += item + ","; 
        SqlCommand cmd = new SqlCommand("Insert into Demo values('" + status+ "')", cn); //Write Your Query to insert into database table        
        int iCount = cmd.ExecuteNonQuery(); 
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900