Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing parent data in nested repeater, in the HeaderTemplate

Simple question, not sure there's a simple answer!

So here's the code: (I've simplified it a lot to make it easier to read)

<asp:Repeater runat="server>
    <ItemTemplate>
        <asp:Repeater runat="server">
            <HeaderTemplate>
                <h1>My header here for: <%# OuterContainer.DataItem.MyItemName %> </h1>
            </HeaderTemplate>
            <ItemTemplate>
                My items code here
            </ItemTemplate>
        </asp:Repeater>
    </ItemTemplate>
</asp:Repeater>

How, in the HeaderTemplate - can I access the DataItem in the parent repeater?

like image 277
Paul Avatar asked Sep 11 '09 14:09

Paul


3 Answers

I have found the answer actually:

Use:

<HeaderTemplate>
    <%# ((RepeaterItem)Container.Parent.Parent).DataItem %>
</HeaderTemplate>
like image 108
Paul Avatar answered Nov 16 '22 06:11

Paul


Solution given by Paul didn't work for me, but this did:

<%# DataBinder.Eval(Container.Parent.Parent, "DataItem.YourProperty")%> 
like image 37
greenoldman Avatar answered Nov 16 '22 06:11

greenoldman


This is an old thread, but it seems proper to add:

In my case I have 2 nested ASPxGridView controls (DevExpress) and Container.Parent.Parent didn't work.

To access parent's data item from child, this is what worked for me:

<%# DataBinder.Eval(Container.NamingContainer.NamingContainer, "DataItem.DbField")%>
like image 10
bobetko Avatar answered Nov 16 '22 06:11

bobetko