從List填充GridView,所以我不得不使用TemplateField控件來允許編輯。這需要在編輯模式下顯示填充了原始值的文本框,並使用FindControl在更新提交時獲取新值。GridView中的FindControl(「someTextBox」)不發送更新的值
問題是foundTextBox.Text == 「OriginalTextBoxValue」
<asp:TemplateField HeaderText="A Field">
<ItemTemplate>
<asp:Label ID="_theLabel" runat="server" Text='<%# Eval("AField") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="_theTextBox" runat="server" Text='<%# Eval("AField") %>' />
</EditItemTemplate>
</asp:TemplateField>
在我更新事件處理程序的代碼
TextBox newText = (TextBox)_myGridView.Rows[e.RowIndex].FindControl("_thTextBox");
//newText.Text == the old value of the text box
我有類似的問題,雖然我認爲這是發生了什麼,但我並不真正瞭解如何解決它。 – sylverfyre 2013-02-06 17:52:49