How to find controls in a repeater header or footer How to find controls in a repeater header or footer asp.net asp.net

How to find controls in a repeater header or footer


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

To find a control in the header:

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

To find a control in the footer:

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

With extension methods

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


Better solution

You can check item type in ItemCreated event:

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


You can take a reference on the control on the ItemCreated event, and then use it later.