Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Nested repeaters -- accessing data from outer repeater

0 views
Skip to first unread message

jerem...@gmail.com

unread,
Oct 7, 2005, 4:52:25 PM10/7/05
to
With nested repeaters, how can I access the outer repeater's DataItem
from the inner repeater?

Here's a snippet from my aspx:

<asp:repeater id="OuterRepeater" runat="server"
onItemDataBound="PrepareInner">
<ItemTemplate>
<h1>
<%# DataBinder.Eval(Container.DataItem, "number") %>
<%# DataBinder.Eval(Container.DataItem, "title") %>
</h1>
<asp:repeater id="InnerRepeater" runat="server">
<ItemTemplate>
<h2>
<%# DataBinder.Eval(OuterContainer.DataItem, "number") %>.
<%# DataBinder.Eval(Container.DataItem, "number") %>
<%# DataBinder.Eval(Container.DataItem, "title") %>
</h2>
</ItemTemplate>
</asp:repeater>
</ItemTemplate>
</asp:repeater>

And here's the method that binds the inner repeater's data source on
each pass using the relation:

public void PrepareInner(Object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item
|| e.Item.ItemType == ListItemType.AlternatingItem)
{
((Repeater)e.Item.FindControl("InnerRepeater")).DataSource=
((DataRowView)e.Item.DataItem).CreateChildView("Relation");
((Repeater)e.Item.FindControl("InnerRepeater")).DataBind();
}
}

Where I used the (invalid) variable "OuterContainer" in the aspx, I
would like to access the Container from OuterRepeater.

cbDevelopment

unread,
Nov 13, 2005, 4:15:46 PM11/13/05
to
If you are doing it in the ASPX as you are, you can get at the parent
repeater item by using:

<%#databinder.eval(container,"Parent.Parent.DataItem")%>

If you are using it the code behind duing an ItemDataBound event, use:

CType(e.Item.Parent.Parent, RepeaterItem).DataItem

BTW, the first parent is the inner Repeater.

Hope this helps.

jerem...@gmail.com wrote in news:1128718345.036264.44100
@z14g2000cwz.googlegroups.com:

0 new messages