一般在 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

ASP.NET 魔法學院


DotBlogs Tags: GridView TemplateField
標題 *
名稱 *
Email (將不會被顯示)
Url
回應
登入後使用進階評論
Please add 3 and 3 and type the answer here: