Code:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
conn.Open();
int idx = e.RowIndex;
GridViewRow row1 = GridView1.Rows[idx];
// string s = row1.Cells[0].Text;
TextBox name = (TextBox)row1.Cells[1].Controls[0];
TextBox course = (TextBox)row1.Cells[2].Controls[0];
TextBox age = (TextBox)row1.Cells[3].Controls[0];
TextBox sex = (TextBox)row1.Cells[4].Controls[0];
TextBox dob = (TextBox)row1.Cells[5].Controls[0];
TextBox address = (TextBox)row1.Cells[6].Controls[0];
TextBox contctno = (TextBox)row1.Cells[7].Controls[0];
TextBox mailid = (TextBox)row1.Cells[8].Controls[0];
string qd = "update Student set Name='" + name.Text + "',Course='" + course.Text + "',Age=" + age.Text + ",Sex='" + sex.Text + "',DateofBirth='" + dob.Text + "',Address='" + address.Text + "',Contactno=" + contctno.Text + ",Email='" + mailid.Text + "' where Contactno=" + contctno.Text + "";
SqlCommand cmd=new SqlCommand(qd,conn);
cmd.ExecuteNonQuery();
GridView1.EditIndex = -1;
GridView1.DataBind();
conn.Close();
fillgv();
}
Comment