前一版本http://www.jb51.net/article/33251.htm是用Javascript獲取GridView的行索引。
此篇Insus.NET使用非Javascript獲取GridView的行索引。
數據還是使用前一篇的數據來更改。
首先為GridView的控件寫OnRowCreated ="GridViewCosmetic_RowCreated"
復制代碼 代碼如下:
Protected Sub GridViewCosmetic_RowCreated(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.FindControl("LinkButton1") IsNot Nothing Then
Dim link As LinkButton = DirectCast(e.Row.FindControl("LinkButton1"), LinkButton)
AddHandler link.Click, AddressOf link_click
End If
End If
End Sub
Private Sub link_click(sender As Object, e As EventArgs)
Dim link As LinkButton = DirectCast(sender, LinkButton)
Dim gvr As GridViewRow = DirectCast(link.Parent.Parent, GridViewRow)
Response.Write("<scr" & "ipt>alert('你選擇的行索引是:" & gvr.RowIndex & "')</scr" & "ipt>")
End Sub