如何访问列表视图的layouttemplate中的控件? [英] How to access controls in listview's layouttemplate?
本文介绍了如何访问列表视图的layouttemplate中的控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从后面的代码中在ListView
的LayoutTemplate
中设置用户控件的属性?
How do I set a property of a user control in ListView
's LayoutTemplate
from the code-behind?
<asp:ListView ...>
<LayoutTemplate>
<myprefix:MyControl id="myControl" ... />
</LayoutTemplate>
...
</asp:ListView>
我想这样做:
myControl.SomeProperty = somevalue;
请注意,我的控件不在ItemTemplate
中,而是在LayoutTemplate
中,因此并非所有项目都存在,它仅存在一次.因此,我应该能够访问一次,而不是针对每个数据绑定项.
Please notice that my control is not in ItemTemplate
, it is in LayoutTemplate
, so it does not exist for all items, it exists only once. So I should be able to access it once, not for every data bound item.
推荐答案
要设置LayoutTemplate内部控件的属性,只需在ListView控件上使用FindControl方法即可.
To set a property of a control that is inside the LayoutTemplate, simply use the FindControl method on the ListView control.
var control = (MyControl)myListView.FindControl("myControlId");
这篇关于如何访问列表视图的layouttemplate中的控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文