一、我以一個簡單的範例來回答您,關於您提到沒有辦法抓到值,由於您抓的是Label,但是label在編輯狀態下沒有出現,所以抓不到值,正確的抓法為Ctype(GridView1.Rows(index).cell(cellindex).control(0),TextBox).Text。
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
Dim editIndex As Integer = GridView1.EditIndex
End Sub
Protected Sub GridView1_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles GridView1.RowUpdated
Dim editIndex As Integer = GridView1.EditIndex
Response.Write(GridView1.Rows(editIndex).Cells(4).Text) '這是抓cell裡面的Label(即是非編輯狀態下的Label,抓不到值)
Response.Write(CType(GridView1.Rows(editIndex).Cells(4).Controls(0), TextBox).Text) '這是抓cell裡面的TextBox(即是編輯狀態下的TextBox,抓的到值)
End Sub
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Dim editIndex As Integer = GridView1.EditIndex
Response.Write(GridView1.Rows(editIndex).Cells(4).Text)'這是抓cell裡面的Label(即是非編輯狀態下的Label,抓不到值)
Response.Write(CType(GridView1.Rows(editIndex).Cells(4).Controls(0), TextBox).Text)'這是抓cell裡面的TextBox(即是編輯狀態下的TextBox,抓的到值)
End Sub
二、要判斷哪一筆被編輯,可以使用GridView1.EditIndex
********************************************************************************
抓取某欄位更新的值或更新前的值可以使用
在RowUpdated屬性中使用
string a = e.NewValues[0].ToString(); //更新的值
string a = e.OldValues[0].ToString(); //更新前的值
沒有留言:
張貼留言