开发者

Nested Repeater not being recognised in code behind

开发者 https://www.devze.com 2023-01-31 15:46 出处:网络
I have a nested repeater set up but the child repeater control is not being recognised in the code behind.It\'s not even being added to the desi开发者_如何学编程gner file.I\'ve tried this on an aspx a

I have a nested repeater set up but the child repeater control is not being recognised in the code behind. It's not even being added to the desi开发者_如何学编程gner file. I've tried this on an aspx and an ascx page but both gives the same problem.

<asp:Repeater ID="RepeaterParent" runat="server">
    <ItemTemplate>

        <asp:Repeater ID="RepeaterChild" runat="server">
        </asp:Repeater>

    </ItemTemplate>
</asp:Repeater>

with this on the page the code behind only recognises the RepeaterParent but not RepeaterChild.

Can anyone help me out here? Many thanks!


Like any other control that is used within a repeater (or template) control, you need to retrieve the control using FindControl.

So, in your item data bind event handler for the parent, you would do:

var childRepeater = RepeaterParent.FindControl("RepeaterChild") as Repeater;


The RepeaterChild will be accessible when you use FindControl("RepeaterChild") on the parent repeater I think. Can't remember the exact syntax.

Also note that the FindControl method will also take the context of the current item of the parent repeater, as the name you specify will repeat. Naming containers do some work in the background to provide unique naming, but it is hard to track sometimes.

0

精彩评论

暂无评论...
验证码 换一张
取 消