【问题标题】:Control Drop Down List from code behind从后面的代码控制下拉列表
【发布时间】:2015-08-26 02:00:14
【问题描述】:

我有许多动态创建的下拉列表和按钮。 我需要编写一段代码,在用户点击某个按钮后更新(在本例中将 enabled 设置为 false)下拉列表。因为一切都是动态创建的,所以我必须使用 Request.Form.AllKeys 来查找下拉列表的 ID。我可以做到这一点。但是,在我找到 ID 后,我无法以任何方式更新 ddl。我怎样才能做到这一点?

    For Each ddlID In Request.Form.AllKeys
      If ddlID Like "ddl_*_" & number Then

      '' Need to figure out how to control the ddl from this point
      ddlID.


      End If
    Next

【问题讨论】:

    标签: asp.net vb.net


    【解决方案1】:

    利用FindControl 方法并将结果转换为 DropDownList:

    Dim yourDropDownInstance as DropDownList = CType(Page.FindControl("ddl_" & number), DropDownList))
    

    注意 1:您将 ID 传递给 FindControl 方法。

    注意 2:在您添加 DropDownLists 的任何控件中使用 FindControl。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-01
      • 1970-01-01
      • 2018-04-27
      • 1970-01-01
      相关资源
      最近更新 更多