Click here to Skip to main content
15,889,838 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi can anyone help me how to update the database value when the check box in grid view is checked using c#


thank you in advance
Posted

1 solution

Try this, it works for me, should work for u.


protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
string constr = ConfigurationManager.ConnectionStrings["connstr"].ToString();
SqlConnection con = new SqlConnection(constr);

string id = (((Label)row.FindControl("lblid")).Text).ToString();

string comments = (((TextBox)row.FindControl("txtcomments")).Text).ToString();
// string grant = (((CheckBox)row.FindControl("CheckBox1")).Checked).ToString();

if (((CheckBox)row.FindControl("CheckBox1")).Checked == true)
{
con.Open();
SqlCommand CmdSql = new SqlCommand("Update leave set admin_comments='" + comments + "', granted='" + true + "' where id=" + id + " ", con);
CmdSql.ExecuteNonQuery();
GridView1.EditIndex = -1;
con.Close();
gridpop();
}

else
{
con.Open();
SqlCommand CmdSql = new SqlCommand("Update leave set admin_comments='" + comments + "', granted='" + false + "' where id=" + id + " ", con);
CmdSql.ExecuteNonQuery();
GridView1.EditIndex = -1;
con.Close();
gridpop();

}
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900