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
- protected void cmdsubmit_Click(object sender, EventArgs e)
- {
- foreach (ListItem item in CheckBoxList1.Items)
- {
- if (item.Selected.Equals("READ"))
- {
- SqlDataSource1.InsertParameters["hobbies"].Name = CheckBoxList1.SelectedItem.Value.ToString();
- }
- if (item.Selected.Equals("WRITE"))
- {
- SqlDataSource1.InsertParameters["hobbies"].DefaultValue = CheckBoxList1.SelectedItem.Value.ToString();
- }
- }
- SqlDataSource1.Insert();
- GridView1.Visible = true;
- }
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 ??