【问题标题】:How to get ClientID for control generated for a BoundField in ASP.NET?如何获取为 ASP.NET 中的 BoundField 生成的控件的 ClientID?
【发布时间】:2011-01-09 16:42:42
【问题描述】:

我有一个包含 BoundFields 的表单,我需要获取与表单中每个 BoundField 关联的控件的 ClientID。 我该怎么做?

UPD:我没有控制 ID。我所拥有的只是不能有 id 的绑定字段。

UPD2:我正在尝试编写这样的代码:

public IDictionary<BoundField, string> GetCliendIDs(FormView formView)
{
    // How to find Client IDs for controls which were created for BoundFields
}

【问题讨论】:

    标签: asp.net forms clientid boundfield


    【解决方案1】:

    试试这个:

    yourForm.FindControl("yourControl").ClientID.ToString();
    

    其中“yourcontrol”是表单中控件的 ID。可以通过源码模式打开aspx页面,查看控件的ID值找到这个值。

    此外,如果您知道它们在表单控件中的位置,您可以访问绑定字段,例如:

    yourform.Controls[0].ClientID //first control 
    yourform.Controls[1].ClientID //second control 
    

    【讨论】:

    • 不同意...我的回答提供了更多详细信息和格式正确的代码示例。此外,您编辑了答案以包含我提供的答案的详细信息... :)
    • @Artem 也许,请将您的一些代码添加到问题中,或者告诉我们更多您想要完成的工作,以便我们为您提供更详细的答案。可能有更好的方法来做你想做的事情
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-22
    • 2015-04-22
    • 2012-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多