kindly help me ...
public partial class courses : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{ }
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{ string interests = string.Empty;
foreach (ListItem item in this.checkbox.Items)
if (item.Selected)
{
interests += item.Text;
SqlCommand cmd = new SqlCommand("Insert into tbl3(courseId) values('" + interests + "')", con); //Write Your Query to insert into database table
con.Open();
int iCount = cmd.ExecuteNonQuery();
con.Close();
}
}
}
Satyapriya NayakPosted May 8, 2013, 12:34 AM
romasha aliPosted May 8, 2013, 6:07 PM
Bryian TanPosted May 7, 2013, 9:21 PM
Did you post the wrong code? The reason I'm asking because the code iterating the checboxlist look fine but the code is trying to insert selected text into courseID column. Maybe the question is about checkboxlist binding? Here is the code snippet to data bind checkboxlist.
CheckBoxList1.DataSource = "yourdatasource";
CheckBoxList1.DataTextField = "Column Name to display as Text";
CheckBoxList1.DataValueField = "Column Name to display as Value";
CheckBoxList1.DataBind();