我想根据gridview的选定行更改两个标签的文本。
我一直收到错误消息,指出公共成员行在linkbutton上不存在
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim LinkButton1 As LinkButton = DirectCast(sender, LinkButton)
Dim tour As Label = CType(sender.Row.FindControl("label2"), Label)
Dim depart As Label = CType(sender.Row.FindControl("label3"), Label)
test.Text = tour.Text
test1.Text = depart.Text
UpdatePanel9.Update()
End Sub
答案 0 :(得分:1)
根据您的代码,sender
是LinkButton
。引用Row
时,属性sender.Row
将不会出现在链接按钮上。这就是你得到错误的原因。
您希望挂钩SelectedIndexChanged事件,这样您就可以更轻松地访问该行。
Sub MyGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim myGrid As GridView = TryCast(sender, GridView)
Dim selectedRow As GridViewRow = myGrid.SelectedRow
'do something with selected row as needed from here.....
End Sub