469,578 Members | 1,863 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,578 developers. It's quick & easy.

Want to store multiple checkboxlists selected value in SQL2005

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
  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.  }

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
1 2878
3,237 Expert 2GB
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.

Similar topics

7 posts views Thread by Felix Natter | last post: by
2 posts views Thread by areef.islam | last post: by
2 posts views Thread by murraymiken | last post: by
3 posts views Thread by Andreas Wöckl | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.