我想知道如何在 Asp.Net Repeater 控件的 HeaderTemplate 或 FooterTemplate 中找到控件。
我可以在 ItemDataBound 事件上访问它们,但我想知道如何在之后获取它们(例如检索页眉/页脚中的输入值)。
注意:我在找到答案后将这个问题发布在这里,只是为了记住它(也许其他人可能会发现这很有用)。
正如评论中所述,这仅在您对中继器进行数据绑定后才有效。
找到一个控件header:
lblControl = repeater1.Controls[0].Controls[0].FindControl("lblControl");
找到一个控件footer:
lblControl = repeater1.Controls[repeater1.Controls.Count - 1].Controls[0].FindControl("lblControl");
具有扩展方法
public static class RepeaterExtensionMethods
{
public static Control FindControlInHeader(this Repeater repeater, string controlName)
{
return repeater.Controls[0].Controls[0].FindControl(controlName);
}
public static Control FindControlInFooter(this Repeater repeater, string controlName)
{
return repeater.Controls[repeater.Controls.Count - 1].Controls[0].FindControl(controlName);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)