Pregunta

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();
}
¿Fue útil?

Solución

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"];

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top