tags:

views:

212

answers:

2

Hi,

I have a bit of code that determine whether or not a control (within a repeater) should be visible or not and I want to call this on Page_Load but I can't seem to get the Controls inside a repeater.

<asp:Repeater ID="repreat" runat="server" >
        <HeaderTemplate>
         <asp:PlaceHolder runat="server" ID="thActivePrimary">Blah</asp:PlaceHolder>
         <asp:PlaceHolder runat="server" ID="PlaceHolder1">Blah</asp:PlaceHolder>
        </HeaderTemplate>
        <ItemTemplate>
         <asp:PlaceHolder runat="server" ID="trActivePrimary">Blah</asp:PlaceHolder>
         <asp:PlaceHolder runat="server" ID="thActivePrimary2">Blah</asp:PlaceHolder>
        </ItemTemplate>              
</asp:Repeater>

repreat.Controls is always empty.

How do I achieve this?

+1  A: 

The controls are not created at page load, They are created when databind is called. If you want to access each item as they are created have a look at the DataBound event of the repeater.

Or bind the visible attribute to your datasource

Adrian
+2  A: 
    foreach (RepeaterItem ri in repeat.Items)
         ri.FindControl("thActivePrimary").Visible = false;

This should work

Fiur