.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

How to insert data of selected checkboxlist control in database.. (sql server)

Posted By: Nehal     Posted Date: October 29, 2009    Points:2   Category :ASP.Net
how to store checkboxlist data into database using asp.net with c#...

For example i have under hobbies list: music,reading,watchingTV,playing,chatting,singing,cooking,dancing

In this list If i select music,reading and playing from the checkboxlist and click button the items selected should to be stored in backend table for particular user..how to do this ...Please Explain me with an example..
I have created 3 tables.
1 is user.-->user_id, user_name
2 is event--> event_id, event_name, event_provider
3 is event_user--> event_id, user_id, date.
so that i can find the whole list which particuler user have selected how many and which events...

Author: Amit Mehra             
Posted Date: October 29, 2009     Points: 5   

Hi Nehal,

Please refer this post to get the data from checkboxlist and save into SQL Server..


Please "Mark As Answer " if this post help you.
Author: Ashutosh Jha             
Posted Date: December 05, 2013     Points: 20   

Hi Nehal,

To insert selected value to database-

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

SqlCommand cmd = new SqlCommand("Insert into tblname values('" + s1 + "')", cn); //
int i = cmd.ExecuteNonQuery();

to select on "onpageevent"-

void LoadCheckList()
string s1 = "";
SqlCommand cmd = new SqlCommand("Select s1 from tblname", conn2);
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
s1= dr["s1"].ToString();
string[] a1 = s1.Split(',');
foreach (ListItem item in this.CheckBoxList1.Items)
foreach (string s in a1)
if (item.Text== s)
item.Selected = true;

Ashutosh Jha


Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend