如何在DataGrid中检索数据绑定文本框的更改值

问题描述:

ASP.NET 1.1-我在ASPX页面上有一个DataGrid,该页面是数据绑定的,并在文本框中显示一个值。用户可以更改此值,然后单击一个按钮,该按钮后面的代码基本上会遍历网格中的每个DataGridItem,对文本框ID进行FindControl,然后将.Text值分配给变量,该变量随后用于更新数据库。 DataGrid随新值反弹。

ASP.NET 1.1 - I have a DataGrid on an ASPX page that is databound and displays a value within a textbox. The user is able to change this value, then click on a button where the code behind basically iterates through each DataGridItem in the grid, does a FindControl for the ID of the textbox then assigns the .Text value to a variable which is then used to update the database. The DataGrid is rebound with the new values.

我遇到的问题是,在将.Text值分配给变量时,要检索的值是原始数据绑定值,而不是新输入的用户值。关于可能导致这种行为的任何想法吗?

The issue I'm having is that when assigning the .Text value to the variable, the value being retrieved is the original databound value and not the newly entered user value. Any ideas as to what may be causing this behaviour?

代码示例:

foreach(DataGridItem dgi in exGrid.Items)
{
    TextBox Text1 = (TextBox)dgi.FindControl("TextID");
    string exValue = Text1.Text; //This is retrieving the original bound value not the newly entered value
    // do stuff with the new value
}

$做事b $ b

所以代码示例来自您的按钮单击事件?

So the code sample is from your button click event?

您确定吗?不会在回发时重新绑定您的数据源?

Are you sure you are not rebinding your datasource on postback?