Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to dynamically render an html menu or unordered list from a dataset that contains my sitemap, i'm stuck here can anyone help. Please it is urgent. Thanks.


VB
Private Sub LoadXML()
       Dim IsAuthorised As Boolean = False
       Dim dr As DataRow = Nothing
       dsSiteMap.ReadXml(Server.MapPath("~/web.sitemap"))
       Dim LastSlashOccurence As Integer = 0
       Dim NodeUrl As String = ""
       Dim sb As StringBuilder = New StringBuilder

       For Each dr In dsSiteMap.Tables(0).Rows
           If dr.Item(1).ToString <> "" And dr.Item(1).ToString <> "~/IACC_Home.aspx" Then
               LastSlashOccurence = dr.Item(1).ToString.LastIndexOf("/") + 1
               NodeUrl = dr.Item(1).ToString.Substring(LastSlashOccurence, (Len(dr.Item(1).ToString) - LastSlashOccurence))
               For Each RoleUrl In Session("UserMenuRoles").Split(New Char() {";"c})
                   If RoleUrl = "All" Then
                       IsAuthorised = True
                       Exit For
                   End If
                   If RoleUrl = NodeUrl Then
                       IsAuthorised = True
                       sb.Append("<ul>")
                       sb.Append("<li id=navselected class=""navsingle nav0""><a href=" & dr.Item(1).ToString & " class=""navstaticlink"">" & dr.Item(3) & "</a></li>")
                       sb.Append("</ul>")
                       Dim
                       Exit For
                   End If
               Next
           End If
         
       Next
   End Sub
Posted
Updated 7-Dec-10 3:45am
v4

1 solution

You've added all your ul/li elements as plain text in your string builder, but you haven't added it to your document and you're not returning the text in the function.

You'll need to output the text from your string builder (sb.ToString()) and then add that text to the document.

An alternate approach would be to just use the site map control which works as above without any code. For a really dynamic menu, use the freely available sql-based site map provider. No need to re-invent the wheel. ;)

Cheers.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900