开发者

change the text of two labels based on the selected row of a gridview

开发者 https://www.devze.com 2023-03-04 02:54 出处:网络
I want to change the text of two labels based on the selected row of a gridview. I keep getting an error that says the public member row does not exist on linkbutton

I want to change the text of two labels based on the selected row of a gridview.

I keep getting an error that says the public member row does not exist on 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(sende开发者_如何学Cr.Row.FindControl("label3"), Label)

    test.Text = tour.Text
    test1.Text = depart.Text

    UpdatePanel9.Update()

End Sub


According to your code, sender is a LinkButton. The property Row won't exist on a link button when you reference sender.Row. That's why you get the error.

You want to hook into the SelectedIndexChanged event, which will give you access to the Row more easily.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消