我在 gridview 上应用编辑功能。
当我的代码控件处于 rowupdating 事件中时,我发现我正在从文本框中获取先前的值(即在我在文本框中进行编辑之前的值)。
以下是我的代码:
Protected Sub gvBooking_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvBooking.RowUpdating
'Dim name As String = DirectCast(gvBooking.Rows(e.RowIndex).FindControl("txtperson1"), TextBox).Text
Dim nname As String = (gvBooking.DataKeys(e.RowIndex).Values("person_name").ToString)
Dim id As Integer = Integer.Parse(gvBooking.DataKeys(e.RowIndex).Value.ToString)
Dim carname As String = gvBooking.DataKeys(e.RowIndex).Values("car_name").ToString
Dim carac As String = ""
'Dim sql As String = ""
'sql = "update dbo.tbl_Book set person_name='" + name + "',ac_type='" + carac + "' where booking_id = " + id.ToString
'gc.ExecuteCommand(sql)
'gvBooking.EditIndex = -1
'gc.BindGridView(gvBooking, "select * from tbl_Book")
End Sub
在此,如果我将人名从 Henry 编辑为 Scott,然后按更新按钮,那么我通过调试器发现 nname 的值仅为 Henry,这是我进行编辑之前的值,而不是它应该具有我编辑的值 Scott .
我不明白我在哪里犯错。
请帮我。