我想知道如何在Asp.Net转发器控件的HeaderTemplate或FooterTemplate中找到控件。
我可以在ItemDataBound事件中访问它们,但我想知道如何在之后获取它们(例如,检索页眉/页脚中的输入值)。
注意:我在找到答案后在这里发布了这个问题,这样我就可以记住它(也许其他人会发现这个问题很有用)。
发布于 2011-02-21 11:13:36
更好的解决方案
您可以在ItemCreated事件中检查项目类型:
protected void rptSummary_ItemCreated(Object sender, RepeaterItemEventArgs e) {
if (e.Item.ItemType == ListItemType.Footer) {
e.Item.FindControl(ctrl);
}
if (e.Item.ItemType == ListItemType.Header) {
e.Item.FindControl(ctrl);
}
}
发布于 2010-08-10 20:56:41
您可以引用ItemCreated事件上的控件,然后在以后使用它。
发布于 2011-04-12 22:43:12
在Repeater中查找控件(页眉、项目、页脚)
public static class FindControlInRepeater
{
public static Control FindControl(this Repeater repeater, string controlName)
{
for (int i = 0; i < repeater.Controls.Count; i++)
if (repeater.Controls[i].Controls[0].FindControl(controlName) != null)
return repeater.Controls[i].Controls[0].FindControl(controlName);
return null;
}
}
https://stackoverflow.com/questions/701412
复制相似问题