这是在 C# 中,但事件与您的目标相同。当用户选择一行时,将触发此事件并检索所选行。获得选定行后,您可以使用列的索引获取该行的任何列值。
void GridView1_SelectedIndexChanged(Object sender, EventArgs e)
{
// Get the currently selected row using the SelectedRow property.
GridView1 row = GridView1.SelectedRow;
// You could access any cell in the row by doing row.cells(index)
MessageLabel.Text = "You selected " + row.Cells[2].Text + ".";
}
希望有帮助!
编辑
VB
Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
' Get the currently selected row using the SelectedRow property.
Dim row As GridViewRow = GridView1.SelectedRow
MessageLabel.Text = "You selected " & row.Cells(2).Text & "."
End Sub