摘要:GridView 的 TemplateField PostBack 時如何取得對應的編輯資料列
一般在 GirdView 的 TemplateField 中的控制項執行 PostBack 時都需要取得目前對應的資料列。
假設在 TemplateField 中有個按鈕 Button1,當 GridView 的某列按鈕執行 PostBack 時,可以利用下述方式取得對應的資料列。
01
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
02
Dim oRow As System.Web.UI.WebControls.GridViewRow
03
Dim iRowIndex As Integer
04
05 '取得 GridView 中對應的 GridViewRow
06
oRow = CType(sender, Button).NamingContainer
07
08 '取得對應的 RowIndex
09
iRowIndex = oRow.RowIndex
10
End Sub

02

03

04

05 '取得 GridView 中對應的 GridViewRow
06

07

08 '取得對應的 RowIndex
09

10
