Reputation: 6194
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?
Upvotes: 4
Views: 1779
Reputation: 632
foreach (RepeaterItem ri in repeat.Items)
ri.FindControl("thActivePrimary").Visible = false;
This should work
Upvotes: 3
Reputation: 6422
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
Upvotes: 1