Method and implementation code for obtaining row index of gridview (non-js Version)

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.