By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,026 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

Want to store multiple checkboxlists selected value in SQL2005

P: 20
Hello friends,

I m using ASP.NET with C# 2005 and SQL SERVER 2005 for the ASP.Net Website.

I m using sqldatasource to connect and retrieve the data from database and then it displays the data in the gridview on the button click event.I have created the stored procedure for insert and select query.

Now in my application i have used checkboxlist where there can be multiple selection for the hobbies.
I want to know how can i store the multiple value into the same column and also want to display it in the gridview all values name.

I can display only the first value from the checkboxlist if at all i select the multiple values...I also want that i can edit or delete the values thru gridview.

Here is the code that i have used just for the reference ::

Expand|Select|Wrap|Line Numbers
  1.  
  2.  protected void cmdsubmit_Click(object sender, EventArgs e)
  3.     {
  4.  foreach (ListItem item in CheckBoxList1.Items)
  5.         {
  6.             if (item.Selected.Equals("READ"))
  7.             {
  8.                 SqlDataSource1.InsertParameters["hobbies"].Name = CheckBoxList1.SelectedItem.Value.ToString();
  9.             }
  10.             if (item.Selected.Equals("WRITE"))
  11.             {
  12.                 SqlDataSource1.InsertParameters["hobbies"].DefaultValue = CheckBoxList1.SelectedItem.Value.ToString();
  13.             }
  14.         }      
  15.         SqlDataSource1.Insert();
  16.         GridView1.Visible = true;
  17.  }
  18.  

Hope this helps anyone to answer.

Pls help me out and rectify my errors.This is just the simple if statements written for only 2contents in checkboxlists.If there are 10contents then what can be done ??
Apr 9 '07 #1
Share this Question
Share on Google+
1 Reply


Motoma
Expert 2.5K+
P: 3,235
The typical way of doing this is through a technique called database normalization. Please take a look at the discussion had in this thread, in particular, read through the links that I posted towards the end of the discussion.
Apr 9 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.