从站点地图创建无序列表 [英] Create Unordered List from Sitemap

查看:114
本文介绍了从站点地图创建无序列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从包含我的站点地图的数据集中动态呈现html菜单或无序列表,我被困在这里,任何人都可以帮忙.请紧急.谢谢.


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.


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

推荐答案

您已将所有ul/li元素添加为字符串生成器中的纯文本,但尚未将其添加到文档中,并且不会在函数中返回文本.

您需要从字符串构建器(sb.ToString())输出文本,然后将该文本添加到文档中.

另一种方法是只使用站点地图控件,该控件可以像上面那样工作,而无需任何代码.对于真正的动态菜单,请使用免费提供的基于sql的站点地图提供程序.无需重新发明轮子. ;)

干杯.
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.


这篇关于从站点地图创建无序列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆