views:

556

answers:

4

ASPX : Code

<asp:repeater id="repeater" runat="server">

<headerTemplate></headerTemplate>

<itemtemplate></itemtemplate>

<footerTemplate> <asp:literal id=findme runate=server> </footerTeplate>

</asp:repeater>

What i am looking for is source code to be able to find the control within the footer of a data repeater. Im familiar with the basic "FindControl" when i do a databind or look for control within the page itself, but how can i find the control within a footer template of a data repeater?

Is this even possible? and if so how can i please get some assistance,

thanks again to all!!!

[update]

i need to be able to do this after the databind

+2  A: 

There are a number of ways that you can do it, the exact way depends on when you want to get access to the control.

If you want it during DataBind, simply do the following inside the item Databound.

if(e.Item.ItemType == ItemType.Footer)
{
    Literal findMe = (Literal)e.Item.FindControl("findMe");
    //Your code here
}

If you want to find it at another point in time, access the repeater's Item collection, then find the "Footer" item, and from that item, you can find the control.

Update

Based on your added note, you can do this by enumerating the item collection, below is an example with a repeater that has an id of myRepeater.

foreach (RepeaterItem item in myRepeater.Items)
{
    if (item.ItemType == ListItemType.Footer)
    {
        Literal findMe = (Literal)item.FindControl("findMe");
        //Do your stuff
    }
}
Mitchel Sellers
I think there is a syntax error in your condition.
Wil P
Thanks, fixed the typo!
Mitchel Sellers
+1  A: 

I think you have to check the ListItemType in an ItemDataBound event handler. You can check for Header or Footer and then use the FindControl method to access the control.

Wil P
Here is an interesting thread on the topic. http://forums.asp.net/p/1255768/2707975.aspx
Wil P
According to posts in the above thread you can only get a reference to nested controls via event handling of a repeaters events. I haven't confirmed this but I do recall from my ASP.NET days that it is true as I have always accessed them from the ItemDataBound event handler. I think you may be able to make a reference to them in the class scope to disable/enable them after data binding has taken place.
Wil P
+1  A: 
Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
    If e.Item.ItemType = ListItemType.Footer Then
        Dim Lit As Literal = CType(e.Item.FindControl("findme"), Literal)
    End If
End Sub
Josh Stodola
A: 
Foreach (RepeaterItem item in myRepeater.Controls)

This will work better as Items collection doesn't contain header and footer

Icen