Iterate over repeater controls

I have some code that determines whether the control (inside the repeater) should be visible or not, and I want to call it on the_Load page, but I cannot get the controls inside the 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?

+4
source share
2 answers

Controls are not created when the page loads. They are created when databind is called. If you want to access each element as they are created, look at the DataBound event of the repeater.

Or bind the visible attribute to your data source

+1
source
  foreach (RepeaterItem ri in repeat.Items) ri.FindControl("thActivePrimary").Visible = false; 

This should work

+3
source

Source: https://habr.com/ru/post/1286460/


All Articles