romasha ali

romasha ali

  • 2k
  • 94
  • 32.5k

ask about checkboxlist

May 7 2013 6:22 PM
i want to store checked items of check box list in database and i got the code but it did not work when i run this code it does not show items in database column rather than it shows "checkbox.DataValueField" in database..code snippet is given below...
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
                int iCount = cmd.ExecuteNonQuery();

Answers (3)