首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在中继器页眉或页脚中查找控件

如何在中继器页眉或页脚中查找控件
EN

Stack Overflow用户
提问于 2009-03-31 15:00:13
回答 7查看 106.7K关注 0票数 120

我想知道如何在Asp.Net转发器控件的HeaderTemplate或FooterTemplate中找到控件。

我可以在ItemDataBound事件中访问它们,但我想知道如何在之后获取它们(例如,检索页眉/页脚中的输入值)。

注意:我在找到答案后在这里发布了这个问题,这样我就可以记住它(也许其他人会发现这个问题很有用)。

EN

回答 7

Stack Overflow用户

发布于 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);
    }
}
票数 54
EN

Stack Overflow用户

发布于 2010-08-10 20:56:41

您可以引用ItemCreated事件上的控件,然后在以后使用它。

票数 5
EN

Stack Overflow用户

发布于 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;
    }
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/701412

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档