以下代码成功运行且没有错误,但我仍然没有从网格中获取新数据,通过添加断点,并且前进,变量中的数据是原始数据,而不是更新的数据,我错过了什么?
Private Sub grvSample_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles grvSample.RowUpdating
Dim row As GridViewRow = DirectCast(grvSample.Rows(e.RowIndex), GridViewRow)
Dim passportNumber As TextBox = DirectCast(row.FindControl("txtNumber"), TextBox)
Dim expiry As TextBox = DirectCast(row.FindControl("txtExpiry"), TextBox)
Dim type As TextBox = DirectCast(row.FindControl("txtType"), TextBox)
Dim name As TextBox = DirectCast(row.FindControl("txtName"), TextBox)
Dim cinvnum As TextBox = DirectCast(row.FindControl("txtCINVNUM"), TextBox)
Dim last As TextBox = DirectCast(row.FindControl("txtLast"), TextBox)
Dim drplist As DropDownList = DirectCast(row.FindControl("DDLNat"), DropDownList)
Dim Conn As New SqlConnection("Data Source=ADMIN-PC;Initial Catalog=T1INV;Integrated Security=True")
Dim cmd As New SqlCommand("update pass_details set passnat='" & drplist.SelectedValue & "', passno='" & passportNumber.Text.Trim() & "', passexp='" & expiry.Text.Trim() & "', passtype='" & type.Text.Trim() & "', nameonpass='" & name.Text.Trim() & "', namelast='" & last.Text.Trim & "' where cinvnum='" & cinvnum.Text.Trim() & "'", Conn) ' where cinvnum='" & grvSample.Rows(e.RowIndex) & "'")
Try
Conn.Open()
cmd.ExecuteNonQuery()
' Refresh the data
grvSample.EditIndex = -1
Dim SSQL = "select * from pass_details"
Dim ds As New DataSet("GET_HIS")
Dim adp As New SqlDataAdapter(SSQL, Conn)
adp.Fill(ds, "TAB_SMT")
grvSample.DataSource = ds.Tables("TAB_SMT")
grvSample.DataBind()
Catch ee As SqlException
Finally
cmd.Dispose()
Conn.Close()
Conn.Dispose()
End Try
End Sub
答案 0 :(得分:1)
我假设您在回发时也正在对GridView
进行数据绑定。这将覆盖更改的值。
因此,请按以下方式在Page_Load中进行检查:
If Not Page.IsPostBack Then
BindGrid()
End If
除此之外GridViewUpdateEventArgs
包含NewNalues
的字典。
Dim passportNumber = e.NewValues("passno")
请注意,它们也在数据绑定上被覆盖。