Search code examples
asp.netrepeaterfindcontrol

ASP.NET Repeater template sub-control visibility before databind


I have a custom control which contains a Repeater control. The Repeater has an ItemTemplate. Inside that item template I have a panel which is going to hide something based on "IsEditable" a boolean property of the custom control. What I would like to do is set the panel's visibility once before the Repeater is databound.

I know I could do an onItemDataBound event and use FindControl to get the panel but that seems a little excessive since it will always be either visible or not for all rows and I have no other actions that need to occur on databind.

Is there a way to find the control in the ItemTemplate before the Repeater is databound?


Solution

  • try this:

    <ItemTemplate>
        <asp:Panel Visible='<%# this.IsEditable %>' runat="server">
            editableStuff
        </asp:Panel>
    </ItemTemplate>