此篇Insus.NET使用非Javascript获取GridView的行索引。
数据还是使用前一篇的数据来更改。
首先为GridView的控件写OnRowCreated ="GridViewCosmetic_RowCreated"
1 Protected Sub GridViewCosmetic_RowCreated(sender As Object, e As GridViewRowEventArgs) 2 If e.Row.RowType = DataControlRowType.DataRow Then 3 If e.Row.FindControl("LinkButton1") IsNot Nothing Then 4 Dim link As LinkButton = DirectCast(e.Row.FindControl("LinkButton1"), LinkButton) 5 AddHandler link.Click, AddressOf link_click 6 End If 7 End If 8 End Sub 9 10 Private Sub link_click(sender As Object, e As EventArgs)11 Dim link As LinkButton = DirectCast(sender, LinkButton)12 Dim gvr As GridViewRow = DirectCast(link.Parent.Parent, GridViewRow)13 14 Response.Write("<scr" & "ipt>alert('你选择的行索引是:" & gvr.RowIndex & "')</scr" & "ipt>")15 End Sub