2014-11-21 68 views
0

我有一个ASP.NET DataGrid,在最后返回三个可点击的列。运行SelectedIndexChanged时,如何返回被点击的项目的值?GridView SelectedIndexChanged - 返回被点击的项目

感谢

enter image description here

Private Sub DG_SelectedIndexChanged(sender As Object, e As EventArgs) 
    Try 
     Dim DG As GridView = CType(sender, GridView) 
     Dim vID As Integer = DG.SelectedRow.Cells(0).Text 
     'Need to determine which item was clicked here 
    Catch ex As Exception 

    End Try 
End Sub 
+0

我有点惊讶,你上面的代码不起作用...几乎我会做。 – Zack 2014-11-21 21:21:59

+0

这是另一种方式:http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedrow(v=vs.110).aspx?cs-save -lang = 1&cs-lang = vb#code-snippet-2 – jyrkim 2014-11-21 21:24:18

+0

Zack - 代码工作并返回被选中的ROW,但我需要知道点击了三列中的哪个链接 – gchq 2014-11-21 21:29:08

回答

0

最后,我发现的唯一办法是一个onclick事件添加到LinkBut​​ton的

AG_Link.Text = "View Agenda" 
AG_Link.Attributes.Add("onclick", "returnDocumentType('Agenda');") 

添加一些JavaScript来更新一个隐藏的文本框,然后拿起结果

Private Sub DG_SelectedIndexChanged(sender As Object, e As EventArgs) 
    Try 
     Dim DG As GridView = CType(sender, GridView) 
     Dim vID As Integer = DG.SelectedRow.Cells(0).Text 
     Dim DocumentType As String = DocumentTypeTB.Text 

    Catch ex As Exception 

    End Try 

End Sub 

一个很长的路,但它的工作原理:-)