如何找到控制在一个中继页眉或页脚 [英] How to find controls in a repeater header or footer

查看:234
本文介绍了如何找到控制在一个中继页眉或页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道怎么一会发现控件一个Asp.Net Repeater控件的HeaderTemplate中或FooterTemplate。

I was wondering how one would find the controls in the HeaderTemplate or FooterTemplate of an Asp.Net Repeater control.

我可以访问他们在ItemDataBound事件,但我不知道如何来后让他们(例如以检索页眉/页脚的输入值)。

I can access them on the ItemDataBound event, but I was wondering how to get them after (for example to retrieve a value of an input in the header/footer).

请注意:我贴在这里找到公正,让我记住它(也许其他人可能会发现这很有用)的答案后,这个问题

Note: I posted this question here after finding the answer just so that I remember it (and maybe other people might find this useful).

推荐答案

由于在评论中指出,当您已经数据绑定您直放站这仅适用。

As noted in the comments, this only works AFTER you've DataBound your repeater.

要找到控制在标题

lblControl = repeater1.Controls[0].Controls[0].FindControl("lblControl");

要找到控制在页脚

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);
    }
}

这篇关于如何找到控制在一个中继页眉或页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆