# [web] [Solved] ASP.Net nested repeaters not quite working...

## Recommended Posts

Moe    1256
I seem to be having some troubles with nested repeaters in ASP.Net. Just doing nested repeaters straight up seems simple enough, and it is. But thats not exactly what I am doing. I have two tables - a parent table and a child table in a database. The child table contains several rows for each row in the parent table. These two tables are loaded into a single DataSet, and the relationship is then established, as so: Adapter.Fill(dataSet); data.Relations.Add("RelationName", data.Tables[0].Columns[0], data.Tables[1].Columns[1], true); data.Relations["RelationName"].Nested = true; I basically want to display the data as follows:
1. Parent 1
• Child of parent 1
• Child of parent 1
• Child of parent 1
2. Parent 2
• Child of parent 2
• Child of parent 2
• Child of parent 2
Simple enough, right? Well, there is one particular line of code that I can't get working. In my .aspx part of the page, I have a line like so, for the nested repeater (the one that gets repeated for each parent row):
 <asp:Repeater ID="Repeater1" runat="server" DataSource='<%# (System.Data.DataRowView)Container.DataItem.Row.CreateChildView("RelationName") %>'>

<!-- more stuff goes here -->

</asp:Repeater>


This should set the data source for the nested repeater, but it doesn't work. It simply explodes when it tries to create that repeater, as there is something wrong with the way that I am getting the DataSource. Here is a tutorial that I have been following, except it uses VB.Net. That, and there is something wrong with that same line (this is the webpage of one of my old college instructors, and when we had to do something similar, he warned us that that line wasn't working. Unfortunately I can't remember what changes needed to be made to it). So, I have done some digging around, and someone else was having a similar problem here. Unfortunately, even after reading that, I still can't quite get it. Anyone? EDIT: fixed messed up lists. EDIT2: I am not too brilliant. Rather than my first posted line of code, I should have had it as follows:
<asp:Repeater ID="Repeater1" runat="server" DataSource='<%# ((System.Data.DataRowView)Container.DataItem).CreateChildView("CategoryForum") %>'>

<!-- stuff goes here -->

</asp:Repeater>


I wasn't doing my cast properly, and I was trying to access the CreateChildView from the Row, not from the DataRowView. Silly me. [Edited by - Moe on November 24, 2007 2:36:30 PM]

##### Share on other sites
gpalin    164
Nested repeaters make my head hurt. Single one is easy enough, but dealing with nesting them complicates things. I'm in the process of getting my head wrapped around the concept.

I did find an interesting article on CodeProject recently that I'm trying to absorb, NestedRepeater. Seems like a way to simplify the nested repeater concept a bit.