I'd like to find out if a certain type of control exists on a page. It's easy enough to iterate through the Controls collection recursively but I'd also like to check on first load whether the control exists in any of the templates (ContentTemplate, EditItemTemplate, ItemTemplate, SelectedItemTemplate etc) contained in a control as well. Does anyone know if its possible, and if so how? There doesn't appear to be a Templates collection per se and it isn't obvious how to query an ITemplate for its contents.
我想知道页面上是否存在某种类型的控件。很容易以递归方式遍历Controls集合,但我还想检查第一次加载是否控件存在于控件中包含的任何模板(ContentTemplate,EditItemTemplate,ItemTemplate,SelectedItemTemplate等)中。有谁知道它是否有可能,如果有的话怎么样?似乎没有模板集合本身,如何查询ITemplate的内容并不明显。
Thanks in advance.
提前致谢。
I don't think I understand your question. A template is used to render multiple copies of a data-bound control (e.g. a data-bound DropDownList in several rows in a GridView come from one template). Trying to find a control in a template like that seems like an exercise in futility.
我认为我不理解你的问题。模板用于呈现数据绑定控件的多个副本(例如,GridView中若干行中的数据绑定DropDownList来自一个模板)。试图在模板中找到一个控件似乎是徒劳的练习。
If you are looking for a control in a specific control that would be rendered by a template (i.e. a specific DropDownList from one of the rows in a GridView) then you could do something like GridView1.Rows[rowIndex].FindControl("myDropDownList"), but you would still be doing this for each control you wanted to find.
如果您正在寻找一个特定控件中的控件,该控件将由模板呈现(即GridView中其中一行中的特定DropDownList),那么您可以执行类似GridView1.Rows [rowIndex] .FindControl(“myDropDownList”)的操作。 ),但你仍然会为你想要找到的每个控件执行此操作。
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2009/06/04/d4dbaa335ed57e457eb0374e23615fb3.html。