Click here to Skip to main content
11,581,130 members (66,299 online)
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 18: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 OriginalGriff 250
1 Frankie-C 185
2 Sergey Alexandrovich Kryukov 85
3 Dave Kreskowiak 83
4 F-ES Sitecore 80
0 OriginalGriff 1,183
1 Sergey Alexandrovich Kryukov 825
2 Abhinav S 597
3 F-ES Sitecore 500
4 Suvendu Shekhar Giri 433


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 14 May 2013
Copyright © CodeProject, 1999-2015
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