Click here to Skip to main content
15,888,301 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a checkbox list that looks like this

<asp:CheckBoxList ID="chkBox" runat="server">
<asp:ListItem Text="Text" Value="Text"/>
<asp:ListItem Text="Email" Value="Email"/>
<asp:ListItem Text="Mail" Value="Mail"/>
<asp:ListItem Text="Calendar" Value="Calendar"/>


I'm not sure what the best way to store this in my SQL database is. I know I can look through the values to append to a string.

But if I want to reload this form and have the checkbox's that were checked off, checked automatically, how should I store this info in my database?

What I have tried:

Here is how I appended these values to a string

string interests = string.Empty;
foreach (ListItem item in this.chkBox.Items)
if (item.Selected)
interests += item + ",";

But I don't think this is ideal. I don't really know how i would pull this out from my table and display it in the form.
Posted
Updated 29-Jul-16 20:17pm

When you store items in database you not only need to store items but also store their checked state. to achieve this, best way to use 'bit' columntype in database it will store true or false value depending upon your checked/unchecked state of listbox
lookout below link for more details
Insert multiple values from CheckBoxList to Database in ASP.Net[^]
 
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