Click here to Skip to main content
15,791,739 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Sir,

I'm developing windows application, in that one small requirement, Ist i'm getting city names from back end populating city names in the check box list,from that check box list what ever i select items i need to store in the back end.

Ex: Suppose if i select 5 items(Checkboxes) out of 10 i need to store five items in the back end.

Please provide the code for how to insert the multiple check boxes in the sql server 2005 by using and how to populate items to front end from back end.

Updated 14-Sep-11 1:15am
Slacker007 14-Sep-11 6:15am    
Edited for readability.

Iterate all the Item of ListBox and check that that item is checked or not.

string citye=string.Empty;
foreach (ListItem item in CheckBoxList1.Items)
               if (item.Selected)
                   city += item.Value + "$";

If you are using single column in your table to store city name you can add a unique separator e.g. $ or # to concatenate city name. (See above code sample)
Share this answer
Herman<T>.Instance 14-Sep-11 6:43am    
to improve speed use a StringBuilder instead of a String.
Based on selected items in checkbox list, create coma (,) seperated string and insert the string in the column.

To populate and to display use following code

arrTemp = Split(IIf(IsDBNull(MyDatarow("DeptName")), "", MyDatarow("DeptName")), ",")
                        For x = 0 To UBound(arrTemp)
                            For y = 0 To chkDepts.Items.Count - 1
                                If chkDepts.Items(y).Value = arrTemp(x) Then
                                    chkDepts.Items(y).Selected = True
                                End If
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