Previous versions of http://www.jb51.net/article/33251.htmare the use of javascriptto obtain the line index of gridview.
In this article, Insus. NET uses non-Javascript to obtain the row index of the GridView.
The data is changed using the data from the previous article.
First, write OnRowCreated = "GridViewCosmetic_RowCreated" for the GridView control"
Copy codeThe Code is as follows:
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" & "ept> alert ('the row index you selected is:" & gvr. RowIndex & "') </scr" & "ept> ")
End Sub