Main Page | Report this Page
.NET DotNet Forum Index  »  ASP.NET Forum  »  Nested repeaters -- accessing data from outer repeater
Page 1 of 1    

Nested repeaters -- accessing data from outer repeater

Author Message
Guest
Posted: Fri Oct 07, 2005 2:52 pm
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
Posted: Sun Nov 13, 2005 4:15 pm
Guest
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.

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

Quote:
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.

 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Mon Dec 07, 2009 10:44 am