简体   繁体   English

Gridview中的值始终为空

[英]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. 我正在尝试触发OnRowUpdating时获取boundfields的值。 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 ? 也许我错了,因为我已经有一段时间没有使用GridView了,但是您不应该访问eNewValues集合吗?

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. 这就是GridView的优点:它可以跟踪旧值和新值,并方便您将它们提供给您,而无需费力去寻找它们。

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. 试试这个,其中CostTextBox是为网格中的控件指定的控件的ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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