Dhimesh Parmar

Dhimesh Parmar

  • NA
  • 126
  • 14.4k

i can'n perform record update using RowUpdating in gridview?

Feb 28 2018 8:18 AM
protected void gridStud_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
LinkButton btn = (LinkButton)gridStud.Rows[e.RowIndex].FindControl("linkUpdate");
int studentId = Convert.ToInt32(gridStud.DataKeys[e.RowIndex].Value.ToString());
TextBox txtStudName = (TextBox)gridStud.Rows[e.RowIndex].FindControl("txtStud");
RadioButton rd1 = (RadioButton)gridStud.Rows[e.RowIndex].FindControl("RadioButton3");
RadioButton rd2 = (RadioButton)gridStud.Rows[e.RowIndex].FindControl("RadioButton4");
TextBox txtBirthdate = (TextBox)gridStud.Rows[e.RowIndex].FindControl("txtDate");
TextBox txtEmail = (TextBox)gridStud.Rows[e.RowIndex].FindControl("txtEmail");
TextBox txtMobile = (TextBox)gridStud.Rows[e.RowIndex].FindControl("txtmob");
studentCommon c = new studentCommon();
SqlCommand cmd = new SqlCommand("studIUD");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("StatementType", "UPDATE");
// cmd.Parameters.AddWithValue("studentId", studentId);
cmd.Parameters.AddWithValue("name", txtStudName);
if (rd1.Checked)
{
cmd.Parameters.AddWithValue("gender", "Male");
}
else
{
cmd.Parameters.AddWithValue("gender", "Female");
}
cmd.Parameters.AddWithValue("brithDate", txtBirthdate);
cmd.Parameters.AddWithValue("emailid", txtEmail);
cmd.Parameters.AddWithValue("mobilenumber", txtMobile);
c.ExecuteNonQueryByCommand(cmd);
gridStud.EditIndex = -1;
gridStud.DataBind();
}

Answers (8)