nested repeater
I am using a nested repeater to generate an unordered list for my site navigation. The problem I have is that I want to generate the following structure.
[list]
<li> item 1 </li>
<li> item 2
[list]
<li>item 2-1 </li>
<li>item 2-2 </li>
<li>item 2-3 </li>
</ul>
</li>
<li>item 3 </li>
</ul>
However what I am getting is [list]
<li> item 1 [list]
</ul>
</li>
<li> item 2
[list]
<li>item 2-1 </li>
<li>item 2-2 </li>
<li>item 2-3 </li>
</ul>
</li>
<li>item 3 [list]
</ul>
</li>
</ul>
Basically the nested child repeater is still writing out its header and footer resulting in[list] </ul> to be generated for every sub item. This means that for every item in my navigation that does not have sub items I still get a drop down due to the[list] and </ul> header and footer tags in the childRepeater. Is there any way I can stop this.
Here's my code. The following runs onLoad of the page.
Sub PopulateMenu()
Const connectionString As String = "SERVER=localhost;DATABASE=db;Integrated Security=True"
Dim con As New SqlClient.SqlConnection(connectionString)
Dim dadCats As New SqlClient.SqlDataAdapter("SELECT tNav.[Nav1ID], tNav.Title, tNav.URL FROM tblNav1 AS tNav ORDER BY tNav.SequenceID", con)
Dim dadSubCats As New SqlClient.SqlDataAdapter("SELECT tNav.[Nav1ID], tNav.[Nav2ID], tNav.Title, tNav.URL FROM tblNav2 AS tNav ORDER BY tNav.SequenceID", con)
Dim dst As New DataSet()
dadCats.Fill(dst, "Sections")
dadSubCats.Fill(dst, "Categories")
dst.Relations.Add("Children", _
dst.Tables("Sections").Columns("Nav1ID"), _
dst.Tables("Categories").Columns("Nav1ID"))
parentRepeater.DataSource = dst.Tables("Sections")
parentRepeater.DataBind()
End Sub
Protected Sub parentRepeater_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles parentRepeater.ItemDataBound
Dim item As RepeaterItem = e.Item
If item.ItemType = ListItemType.Item Or item.ItemType = ListItemType.AlternatingItem Then
Dim childRepeater As Repeater = item.FindControl("childRepeater")
Dim drv As DataRowView = item.DataItem
childRepeater.DataSource = drv.CreateChildView("children")
childRepeater.DataBind()
End If
And in the presentation layer
[list]
<asp:repeater id="parentRepeater" runat="server" OnItemDataBound="parentRepeater_ItemDataBound">
<itemtemplate>
<li><a href='/sections_<%# Container.DataItem("Nav1ID") %>.aspx' class="nav_separator"><%#DataBinder.Eval(Container .DataItem, "Title")%></a>
<asp:repeater id="childRepeater" runat="server">
<HeaderTemplate>
[list]
</HeaderTemplate>
<itemtemplate>
<li><a href='/categories_<%# Container.DataItem("Nav1ID") %>_<%# Container.DataItem("Nav2ID") %>.aspx'><%# Container.DataItem("Title") %></a></li>
</itemtemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</li>
</itemtemplate>
</asp:Repeater>
</ul>
|