gridview line index method and implementation code of non js version

  • 2020-05-19 04:37:51
  • OfStack

1 version before / / www. ofstack. com article / 33251 htm were obtained with Javascript GridView row index.

This article Insus.NET USES non-Javascript to get the row index of GridView.
The data is still changed using the data from the previous article.
First write OnRowCreated ="GridViewCosmetic_RowCreated" for the GridView control
 
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(' The row index you selected is: " & gvr.RowIndex & "')</scr" & "ipt>") 
End Sub 

Related articles: