Access parent data in a nested strongly typed repeater

Lets say I have a class structure that looks something like this:

public class A
{
    public string Poperty1 { get; set; }
    public string Poperty2 { get; set; }
    public List<B> Property3 { get; set; }
}

public class B
{
    public string Property4 { get; set; }
    public string Property5 { get; set; }
}

...and a couple of nested repeaters that look like this:

<asp:Repeater ItemType="A" runat="server">
    <ItemTemplate>
        <asp:Label Text="<%# Item.Property1 %>" runat="server" />
        <asp:Repeater runat="server" DataSource="<%# Item.Property3 %>" ItemType="B">
            <ItemTemplate>
                <asp:Label Text="<%# Item.Property4 %>" runat="server" />
            </ItemTemplate>
        </asp:Repeater>
    </ItemTemplate>
</asp:Repeater>

How would I access Property2 from the second repeater?

Answers


Well, from Accessing parent data in nested repeater, in the HeaderTemplate, I found the following solution. It's not the prettiest, but it works:

<%# ((Container.Parent.Parent as RepeaterItem).DataItem as A).Property2 %>

Need Your Help

Paypal payments pro and pci compliance

php paypal

I've tried sifting through all the discussions online about PCI compliance when using PayPal payments pro, but there's no clear answer. Other than having SSL, since I'm not storing cardholder infor...

SSRS report corrupt when writing to file with WriteAllBytes C#

c# pdf reporting-services corrupt

We have a process that has SQL Server Reporting Services create a pdf file via