I have four check boxes like this,
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
onselectedindexchanged="CheckBoxList1_SelectedIndexChanged" Width="190px">
<asp:ListItem>Programming Contests</asp:ListItem>
<asp:ListItem>Seminars/Workshops</asp:ListItem>
<asp:ListItem>Social Gatherings</asp:ListItem>
<asp:ListItem>Tech Support</asp:ListItem>
</asp:CheckBoxList>
I want to store the value of these check boxes as 0 or 1 in the table. Moreover, there may be a scenario when a user selects more than one check box, how to deal with that situation? I have used the ‘bit’ data type in the database. But the confusion I am having is how to store the value of these check boxes as 0 or 1 in database?
It really is quite simple. All you need to do is create a bit field for each option in your db. I do not see any other logical way of doing it.
The true or false value returned from your checkboxes are called bools in C#. Bools are stored in the database as bits translating true to 1 and false top 0.
Edit:
If you are planning on expanding the options, I would recommend something along the lines of the following. You can create a table that contains all the options and set a code for them. Then create a linking table that will include the person and the option they desire. If the user chooses multiple options, they will be put in the table multiple times (once for each option).