简体   繁体   中英

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();
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM