我正在使用ItemTemplate & EditTemplate編輯gridview。 (ASP.net + VB)。Gridview - 無法獲取RowUpdating更新的單元格值
我點擊編輯按鈕,然後我可以選中/取消選中這些複選框並修改文本框的值。 當點擊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
您好,我得到這個錯誤味精 「索引超出範圍必須爲非負數且小於集合的大小參數名:索引」 後,我停止調用bindata() page_load for!IsPostBack 運行此代碼時發生錯誤: Dim row = Gridview1.Rows(e.RowIndex) –
您能告訴我函數BindData嗎? – naveen