Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0
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 12-May-13 19:31pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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();
 
}
}
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 14 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100