To Update Records Follow :
In aspx page add :
<asp:CommandField ButtonType="Button" ShowEditButton="True" ShowSelectButton="True" />
and implement the gridView's RowEditing , RowUpdating and RowCancelingEdit Events as :
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
/*Code to BindGrid */
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int id = int.Parse(((Label)GridView1.Rows[e.RowIndex].FindControl("lblid")).Text);//ID
string name = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtname")).Text;
SqlConnection connect = new SqlConnection("ConnString");
connect.Open();
string q = "Update people set name=@name where id=@id";
SqlCommand comm = new SqlCommand(q, connect);
comm.Parameters.AddWithValue("name", name);
comm.Parameters.AddWithValue("id", id);
comm.ExecuteNonQuery();
connect.Close();
GridView1.EditIndex = -1;
/*Code to BindGrid */
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
/*Code to BindGrid */
}