我们有一个相当大的菜单结构,包含动态菜单和子菜单,我们试图将其输出到无序列表或下拉列表,但如果我们显示级别3及以下,则需要永久加载页面。我不知道如何加快速度。任何帮助都将非常感激,永远在你的债务中:))
这是菜单menu_dropdown.ascx代码
<%@ Control Language="VB" Inherits="BaseUserControl"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.sqlClient " %>
<script runat="server">
Private sConn As String = ConfigurationManager.ConnectionStrings("SiteConnectionString").ConnectionString.ToString()
Private oConn As New SqlConnection(sConn)
Dim nCount As Integer = 0
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
litMenu.Text = PopulateChildren(Me.InsitePage.root_id)
End Sub
Protected Function PopulateChildren(ByVal nPgId As Integer) As String
Dim sHTML As String = ""
If nCount <= 2 Then
Dim oCommand As SqlCommand
Dim oDataReader As SqlDataReader
oConn.Open()
oCommand = New SqlCommand
If Me.IsUserLoggedIn Then
oCommand.CommandText = "select count(page_id) as count from pages_published where parent_id = @root_id and is_system = 0 and is_hidden = 0"
Else
oCommand.CommandText = "select count(page_id) as count from pages_working where parent_id = @root_id and is_system = 0 and is_hidden = 0"
End If
oCommand.CommandType = CommandType.Text
oCommand.Parameters.Add("@root_id", SqlDbType.Int).Value = nPgId
oCommand.Connection = oConn
oDataReader = oCommand.ExecuteReader()
Dim nInt As Integer = 0
While oDataReader.Read()
nInt = oDataReader("count")
End While
oConn.Close()
If nInt > 0 Then
If nCount = 0 Then
sHTML = "<ul id=""myid2"" class=""dropdown"" data-role=""listview"" data-inset=""true"">"
Else
sHTML = "<ul>"
End If
If nPgId = Me.InsitePage.root_id Then 'if it is the home page (root)
Dim oRootPage As InsitePage = New InsitePage(nPgId, Nothing)
sHTML += "<li><a href=""" & oRootPage.file_name & """ title=""" & Replace(oRootPage.title, """", "\""") & """>" & oRootPage.title & "</a></li>" 'Show Home Page link
End If
Dim listing As List(Of InsiteMenuItem)
listing = New InsiteMenu().GetMenus(nPgId.ToString(), 0, nInt, "main")
For Each root As InsiteMenuItem In listing
sHTML += "<li><a href=""" & root.file_name & """ title=""" & Replace(root.title, """", "\""") & """>" & root.title & "</a>"
If Not root.is_listing Then
nCount = nCount + 1
sHTML += PopulateChildren(root.page_id)
End If
sHTML += "</li>"
Next
sHTML += "</ul>"
If sHTML = "<ul></ul>" Then
sHTML = ""
End If
End If
End If
nCount = nCount - 1
Return sHTML
End Function
</script>
<asp:Literal ID="litMenu" runat="server"></asp:Literal>