Hey guys,
This blogs we explain how
to insert multiple selected checkbox value into database using asp.net.
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["123"].ConnectionString);
protected void btnSubmit_Click(object sender, EventArgs e)
{
string checkit = "";
for (int i = 0; i < chk1.Items.Count - 1; i++)
{
if (chk1.Items[i].Selected == true)
{
checkit = checkit + chk1.Items[i].Text + ",";
}
}
try
{
SqlCommand cmd = new SqlCommand();
string ins;
ins = "Insert into checkme values('" + txtId.Text + "', '" + checkit + "')";
cmd = new SqlCommand(ins, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
lblMsg.Text = "Successfully insert
data";
}
catch (Exception er)
{
lblMsg.Text = er.Message;
}
}
}
No comments:
Post a Comment