Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Nested repeaters -- accessing data from outer repeater

 
Thread Tools Search this Thread
Old 10-07-2005, 09:52 PM   #1
Default 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.



jeremystein@gmail.com
  Reply With Quote
Old 11-13-2005, 09:15 PM   #2
cbDevelopment
 
Posts: n/a
Default Re: Nested repeaters -- accessing data from outer repeater
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.

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




cbDevelopment
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Wonderful data input with web reporting tool freezea Software 0 09-09-2009 05:30 AM
ASP.Net - Data Repeater vbnetman General Help Related Topics 0 01-07-2008 11:34 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46