Nested repeaters -- accessing data from outer repeater


J

jeremystein

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.
 
Ad

Advertisements

C

cbDevelopment

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.

(e-mail address removed) wrote in @z14g2000cwz.googlegroups.com:
 

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