문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top