Search code examples
c#asp.netgridviewboundfield

Value from Gridview is always empty


I have a gridview with boundfields inside the grid. I'm trying to get the values of the boundfields when OnRowUpdating is fired. But when I try to read the new values the result is always empty.

This is the instruction I'm using :

protected void MyGridView_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
{
  string id = MyGridView.Rows[e.RowIndex].Cells[3].Text;
  DataBind();
}

Solution

  • Maybe I'm wrong, since I haven't used the GridView for a while, but shouldn't you be accessing the NewValues collection of e?

    That's the beauty of the GridView: it keeps track of old vs. new values, and conveniently makes them available to you without you having to fish around to find them.

    string id = (string) e.NewValues["whatever"];