I have written the below code for updating gridview, It's not working.

protected void Update_row(object sender, GridViewUpdateEventArgs e)
  //TextBox ID = (TextBox)GridView1.Rows[e.RowIndex].Cells[0].FindControl("txtID");
  TextBox Title = (TextBox)GridView1.Rows[e.RowIndex].Cells[1].FindControl("TextBox1");
  TextBox Name = (TextBox)GridView1.Rows[e.RowIndex].Cells[2].FindControl("TextBox2");

                SPSecurity.RunWithElevatedPrivileges(delegate ()
                    UpdateRow(ID.Text, Title.Text, Name.Text);
                    GridView1.EditIndex = -1;
            catch (Exception ex)
                Label1.Text = ex.ToString();


After debugging I found that the ID, Title and Name values are null.


I found that I did not write the gridview code perfectly, so I made some changes there.

Now I am getting the values in those controls but these values are the already existing value, updated entries are not coming there.

Label ID = (Label)GridView1.Rows[e.RowIndex].Cells[0].FindControl("lblId");
                TextBox Name = (TextBox)GridView1.Rows[e.RowIndex].Cells[1].FindControl("txtName");
                TextBox Title = (TextBox)GridView1.Rows[e.RowIndex].Cells[2].FindControl("txtTitle");

these are just getting the already existing values.

  • Why u commented that ID TextBox? – Jayakumar Kulkarni Mar 8 '16 at 5:39
  • Actually, it's not commented...But still it takes null – KumarV Mar 8 '16 at 5:42
  • i got it.. It was the ispostback event that needed to be used. – KumarV Mar 8 '16 at 10:07


 GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];         
    TextBox ID = (TextBox)row.FindControl("txtID");
    TextBox Title = (TextBox)row.FindControl("TextBox1");
    TextBox Name = (TextBox)row.FindControl("TextBox2");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.