Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To expand on Kelsey's answer (which I would vote up if I had enough rep here, but this is my very first post on StackExchange - but I will when I'm able! EDIT: I've up-voted it!), here's some code that may help, since I had to do this exact thing (with using different types of groups, but essentially it's the same), and Kelsey's answer helped me too.</p> <p>Note that this is probably not perfect, but it does work for me. I'm interested in improving it. It is ever-so-slightly different than Kelsey's approach.</p> <p>In my case, I am using 3 levels of nested repeaters in a navigation menu in an ASP.NET (VB) application. </p> <p>First, set up a dataset to bind to the parent repeater in your code-behind. (I know you said you aren't interested in answers with datasets or datatables, but I'm not sure of a better way - SOMETHING must be databound to the repeaters...)</p> <pre><code>' first load up some datatables with some data. ' you will probably want to optimize how you are grabbing the data Dim dtCategories As DataTable = GetCategories Dim dtQuestionGroups As DataTable = GetQuestionGroups Dim dtQuestions As DataTable = GetQuestions ' name the tables dtCategories.TableName = "Categories" dtQuestionGroups.TableName = "QuestionGroups" dtQuestions.TableName = "Questions" ' add the datatables to a dataset and set some relationships Dim ds As DataSet = New DataSet ds.Tables.Add(dtCategories) ds.Tables.Add(dtQuestionGroups) ds.Tables.Add(dtQuestions) ' note that your column name identifiers may be different. ds.Relations.Add("CatQgrp", _ ds.Tables("Categories").Columns("id"), _ ds.Tables("QuestionGroups").Columns("CatID")) ds.Relations.Add("QgrpQues", _ ds.Tables("QuestionGroups").Columns("id"), _ ds.Tables("Questions").Columns("QgrpID")) ' bind to repeater. only need to bind the parent table parentRepeater.DataSource = ds.Tables("Categories") parentRepeater.DataBind() </code></pre> <p>So now that we have the data set up, we can display it on the aspx page.</p> <pre><code>&lt;ul&gt; &lt;li&gt;CATEGORIES &lt;ul&gt; &lt;asp:repeater id="parentRepeater" runat="server"&gt; &lt;itemtemplate&gt; &lt;li&gt;&lt;%# DataBinder.Eval(Container.DataItem, "CategoryName")%&gt; &lt;ul&gt; &lt;!-- start child repeater 1, which will show the question groups--&gt; &lt;asp:repeater id="childRepeater1" datasource='&lt;%# Container.DataItem.Row.GetChildRows("CatQgrp") %&gt;' runat="server"&gt; &lt;itemtemplate&gt; &lt;li&gt;&lt;%# Container.DataItem("QgrpName")%&gt; &lt;ul&gt; &lt;!-- start child repeater 2, which will show the questions--&gt; &lt;asp:repeater id="childRepeater2" datasource='&lt;%# Container.DataItem.GetChildRows("QgrpQues") %&gt;' runat="server"&gt; &lt;itemtemplate&gt; &lt;li&gt;&lt;%# Container.DataItem("QuestionName")%&gt;&lt;/li&gt; &lt;/itemtemplate&gt; &lt;/asp:repeater&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/itemtemplate&gt; &lt;/asp:repeater&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/itemtemplate&gt; &lt;/asp:repeater&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>YMMV, and you'll need to change the column names to whatever you are using in your database tables of course, but this should get you started.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload