GridView SelectedIndexChanged - 返回已单击的项目

时间:2014-11-21 21:17:32

标签: asp.net vb.net gridview

我有一个ASP.NET DataGrid,最后返回三个可单击的列。运行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

1 个答案:

答案 0 :(得分: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

有点长,但有效: - )