I want to be able to write out my navigation using repeaters to generate a <ul> list. eg
<ul>
<li> item 1 </li>
<li> item 2
<ul>
<li>item 2-1 </li>
<li>item 2-2 </li>
<li>item 2-3 </li>
</ul>
</li>
<li>item 3 </li>
</ul>
Only problem is that when the list is generated if a main item contains no sub-items it still writes out the <ul> and </ul> I have defined in the header and footer of my nested repeater and shows an empty drop down menu in my nav. I have tried to get round this but no luck as yet. OnLoad I run this function to populate the repeater with content.
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
This works fine, but to try and remove the extra <ul> </ul> from being generated I used
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("parentRepeater")
childRepeater.DataBind()
End If
End Sub
This is where the error is I get the message
"The relation is not parented to the table to which this DataView points."
Any Ideas???