0

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();
}
Camilla
  • 949
  • 2
  • 14
  • 26
  • does it gives an error – NetStarter Feb 13 '13 at 13:14
  • 1
    Camila can are you binding the data anywhere in code.. hard to tell what's going on with only that one event that you are showing.. for example `MyGridView.DataBind();` try adding that – MethodMan Feb 13 '13 at 13:15
  • Is there an 'OnRowUpdated' method you can subscribe to and run your code in instead? It's my understanding that the GridView isn't updated prior execution of OnRowUpdating, so the row you're trying to access might very well not be in the grid yet. – B L Feb 13 '13 at 13:16
  • After each command (edit, cancel, update..) I bind again the data. @glace I don't have onRowUpdate – Camilla Feb 13 '13 at 13:20
  • I'm following this example http://nareshkamuni.blogspot.it/2012/01/gridview-rowediting-event-in-aspnet.html – Camilla Feb 13 '13 at 13:20
  • http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.onrowupdated.aspx – B L Feb 13 '13 at 13:21
  • Camila show more code please ..hard to determine what the `H311` you are doing.. – MethodMan Feb 13 '13 at 13:24

2 Answers2

0

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"];
Ann L.
  • 13,760
  • 5
  • 35
  • 66
0
TextBox sampleTextBox=((TextBox)MyGridView.Rows[e.RowIndex].FindControl("CostTextBox"));
string data=sampleTextBox.Text;

try this this, where CostTextBox is the id of the control you have given for the control in the grid.

Rudresha Parameshappa
  • 3,826
  • 3
  • 25
  • 39