0

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

Community
  • 1
  • 1
sia
  • 2,185
  • 4
  • 20
  • 17

5 Answers5

3
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
  • 81,538
  • 47
  • 180
  • 227
2

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
  • 62,228
  • 14
  • 110
  • 173
1

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
  • 3,341
  • 1
  • 20
  • 20
  • Here is an interesting thread on the topic. http://forums.asp.net/p/1255768/2707975.aspx – Wil P Nov 30 '09 at 21:27
  • 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 Nov 30 '09 at 21:33
0
Foreach (RepeaterItem item in myRepeater.Controls)

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

Icen
  • 1
0

If you need to get the Footer after DataBind (which is what the OP appears to want) then you can use the following:

RepeaterItem item= (RepeaterItem)myRepeater.Controls[myRepeater.Controls.Count - 1];
if (item.ItemType == ListItemType.Footer) {
    Literal findMe = (Literal)item.FindControl("findMe");
}
TechyGypo
  • 824
  • 1
  • 11
  • 27