根据网格视图的选定行更改两个标签的文本

发布于 2024-11-06 06:44:26 字数 479 浏览 0 评论 0原文

我想根据网格视图的选定行更改两个标签的文本。

我不断收到错误消息,指出链接按钮上不存在公共成员行

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

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(sender.Row.FindControl("label3"), Label)

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

    UpdatePanel9.Update()

End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

负佳期 2024-11-13 06:44:26

根据您的代码,sender 是一个LinkBut​​ton。当您引用 sender.Row 时,链接按钮上将不存在 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文