【问题标题】:Get the selected row of a GridView that's nested in a Repeater获取嵌套在中继器中的 GridView 的选定行
【发布时间】:2016-12-14 02:41:52
【问题描述】:

我的Repeater 中有一个下拉菜单,该下拉菜单根据在嵌套在Repeater 中的Gridview 中选择的行来填充。

我需要根据在 GridView 中选择的行刷新下拉菜单。

通常我可以像这样得到当前选中的行:

Protected Sub GvRevisionInfo2_OnSelectedIndexChanged(sender As Object, e As EventArgs)
    Dim country As String = TryCast(GridView1.SelectedRow.FindControl("lblCountry"), Label).Text
End Sub

但我不知道 GridView 的 ID,因为它是在 Repeater 内部动态生成的。有时有 2 个 GridView,有时有 20 个。

那么如何从代码隐藏中动态生成的 GridView 中的当前选定行中获取值?

【问题讨论】:

  • 尝试以下操作: Protected Sub GvRevisionInfo2_OnSelectedIndexChanged(sender As Object, e As EventArgs) Dim dgvRow As DataGridViewRow = CType(sender, DataGridViewRow) Dim country As String = dgvRow.Cells("lblCountry").Value End子
  • 谢谢。尝试这样做,但未定义 DataGridViewRow。我有导入系统,系统中的win表单中的DataGridViewRow不是吗?
  • 你有 GridViewRowPresenter 而不是 DataGridViewRow 吗?

标签: c# asp.net vb.net gridview


【解决方案1】:

您可以将 sender 转换回 GridView 并使用它。

Protected Sub GvRevisionInfo2_OnSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
    Dim gridView As GridView = CType(sender,GridView)
    Dim label As Label = CType(gridView.SelectedRow.FindControl("lblCountry"),Label)
    Dim country As String = label.Text
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-10
    • 1970-01-01
    • 2014-04-04
    • 2010-09-18
    • 2011-11-13
    • 1970-01-01
    相关资源
    最近更新 更多