我在这个表格中有一个类别的层次表NodeID
ParentID
NodeName
以下是我正在使用的代码生成ASP.NET MENU ITEMS
并将其绑定到MENU CONTROL
Private Sub displayMenu()
Using con As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("HagglerEntLibConStr").ConnectionString)
Using sql As New SqlCommand("Select NodeID,ParentID,NodeName FROM Nodes", con)
con.Open()
Dim r As SqlDataReader = sql.ExecuteReader 'stored procedure that returns the above SqlDataReader
Dim tempMaster As New MenuItem()
Dim bagMaster(700) As MenuItem
Dim j As Integer = 0
Do While r.Read()
tempMaster.Value = r("NodeID").ToString()
tempMaster.ToolTip = r("ParentID").ToString()
tempMaster.Text = r("NodeName").ToString()
tempMaster.NavigateUrl = ""
bagMaster(j) = tempMaster
j += 1
tempMaster = New MenuItem()
Loop
r.Close()
Menu1.Items.Clear()
For i As Integer = 0 To j - 1
If i = 0 Then
Menu1.Items.Add(bagMaster(i))
Else
For x As Integer = 0 To j - 1
If bagMaster(i).ToolTip = bagMaster(x).Value Then
Dim c As MenuItem = bagMaster(x)
'you can change the tool tip here if you want
c.ChildItems.Add(bagMaster(i))
End If
Next x
End If
Next i
'Menu1.Items.RemoveAt(0)
End Using
End Using
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
displayMenu()
End Sub
一切正常......但这种方法的主要缺点是Menu CONTROL
创建HTML TABLES
......我在表格中有大约 1000 行......这创建了一个多级菜单......这HTML Tables
在页面中添加了很多并增加了页面加载时间急剧...我该如何解决这个问题?这是菜单的填充方式。