前一版本https://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
此篇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
标签:
gridview行,索引
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com
暂无“gridview行索引获取方法及实现代码(非js版)”评论...