468,746 Members | 1,828 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,746 developers. It's quick & easy.

Nested repeaters -- accessing data from outer repeater

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")).Da taSource=
((DataRowView)e.Item.DataItem).CreateChildView("Re lation");
((Repeater)e.Item.FindControl("InnerRepeater")).Da taBind();
}
}

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

Nov 19 '05 #1
1 9987
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.DataIt em")%>

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.

je*********@gmail.com wrote in news:1128718345.036264.44100
@z14g2000cwz.googlegroups.com:
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")).Da taSource=
((DataRowView)e.Item.DataItem).CreateChildView("Re lation");
((Repeater)e.Item.FindControl("InnerRepeater")).Da taBind();
}
}

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


Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Ed Allan | last post: by
1 post views Thread by Peter Kirk | last post: by
4 posts views Thread by =?Utf-8?B?SmFtZXMgR2V1cnRz?= | last post: by
reply views Thread by Adam Knight | last post: by
2 posts views Thread by Josh | last post: by
1 post views Thread by andrew.douglas11 | last post: by
3 posts views Thread by Leon Mayne | last post: by
1 post views Thread by CARIGAR | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.