Nested Repeaters

P

Peter Kirk

Hi

in nested repeaters, how do I access data in the "outer" repeater from the
"inner" repeater?

For example, I have an ArrayList of RegionMenuItem objects. These objects
contain a Region object, and an ArrayList of Region objects.
I want to display this hierarchy, and in the inner ArrayList of Region
objects I need to access the Id field of the parent Region object.

<asp:repeater id="outer" runat="server">

<ItemTemplate>
<%# ((RegionMenuItem)Container.DataItem).FromRegion.Name %> <br>

<asp:repeater id="inner" runat="server" DataSource='<%#
((RegionMenuItem)Container.DataItem).ToRegions %>'>
<ItemTemplate>
&nbsp; <%# ((Region)Container.DataItem).Name %> + <%# outerrepeater
region id %> ??? how this ???
</ItemTemplate>
</asp:repeater>

<ItemTemplate>

</asp:repeater>


Thanks for any help,
Peter
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


Interesting situation. Obviously you cannot use Container.DataItem to refer
to the parent.
I would keep a reference to the parent Container.DataItem in a protected
variable declared in the code behind. This variable is accesible to the
inner repeater. so the only thing you need to do is update it when the
external repeater bind the data, like :
<asp:repeater id="outer" runat="server">

<ItemTemplate>
<%# KeepReference( Container.DataItem ) %>

<asp:repeater id="inner" runat="server" DataSource='<%#
((RegionMenuItem)Container.DataItem).ToRegions %>'>
<ItemTemplate>
<%# ((Region) OuterReferenceToItem).Name %>
</ItemTemplate>
</asp:repeater>


in the code behind:
protected object OuterReferenceToItem;
protected void KeepReference ( object o ) { OuterReferenceToItem = o; }


cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top