Gridview-无法获取RowUpdating的更新单元格值

|| 我正在使用ItemTemplate和EditTemplate编辑gridview。 (ASP.net + VB)。 我单击“编辑”按钮,然后可以选中/取消选中那些复选框并修改文本框的值。 当单击UPDATE按钮时,它将触发RowUpdating事件,但是我发现当我获取update语句的值时,它仍会在编辑前获取值,而不是更新后的值。 如何获得最新和更新的价值?谢谢。 乔 以下是VB代码:
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)

    \'Update the values.
    Dim row = Gridview1.Rows(e.RowIndex)

    Dim Col1_SL = CType(Gridview1.Rows(e.RowIndex).FindControl(\"cb1_SL\"), CheckBox)
    Dim Col1_VL = CType(Gridview1.Rows(e.RowIndex).FindControl(\"cb1_VL\"), CheckBox)
    Dim Col1_ML = CType(Gridview1.Rows(e.RowIndex).FindControl(\"cb1_ML\"), CheckBox)
    Dim Col1_PH = CType(Gridview1.Rows(e.RowIndex).FindControl(\"cb1_PH\"), CheckBox)
    Dim Col1_APH = CType(Gridview1.Rows(e.RowIndex).FindControl(\"cb1_APH\"), CheckBox)
    Dim Col1_TOIL = CType(Gridview1.Rows(e.RowIndex).FindControl(\"cb1_TOIL\"), CheckBox)
    Dim Col1_Others = CType(Gridview1.Rows(e.RowIndex).FindControl(\"tb1_Others\"), TextBox)
    Dim Col1_RosterKey = CType(Gridview1.Rows(e.RowIndex).FindControl(\"lb1_rosterkey\"), Label)

    Using conn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings(\"hris_shiftdutyConnectionString\").ConnectionString)
        conn.Open()
        cmd.Connection = conn
        sql = \"SET DATEFORMAT dmy;UPDATE troster SET SL=\'\" & Convert.ToInt32(Col1_SL.Checked) & \"\' where roster_key=\'\" & Col1_RosterKey.Text & \"\';\"
        cmd.CommandText = Sql
        reader = cmd.ExecuteReader()
        conn.Close()
        reader.Close()
    End Using

    \'Reset the edit index.
    Gridview1.EditIndex = -1

    \'Bind data to the GridView control.
    BindData()
End Sub
    
已邀请:
        最可能的原因是这样。 您在
Page_Load
上呼叫
BindData()
而不使用
!IsPostBack
Protected Sub Page_Load Handles Me.Load
    If Not IsPostBack
        \' Bind Grid only at the first load
        \' Do not load Grid again at Postbacks
        BindData()
    End If
End Sub
    
        您有2个选项: 绑定到网格视图的数据源执行更新后,将触发一个单独的RowUpdated方法。此方法将包含用于编辑和插入的新值。 RowUpdating方法应具有GridViewEventArgs类型的参数。这将具有一个名为NewValues的属性,其中包含新值。在您的示例中,这是变量
e
。     

要回复问题请先登录注册