Reputation: 1392
I have a Hierarchical Table for Categories in this form NodeID
ParentID
NodeName
Following is the code i am using generate ASP.NET MENU ITEMS
and bind it to 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
Everything works fine ...but the main disadvantage with this approach is that the Menu CONTROL
creates HTML TABLES
...i have around 1000 rows in the table..this creates a multi level menu ...which adds a lot of HTML Tables
in the page and increases the page load time drastically...how do i tackle this issue?? This is the way the menu populates.
Upvotes: 2
Views: 287
Reputation: 21365
Have you tried with the RenderingMode property?
Values:
Default. (This is the default value). The rendering mode depends on the RenderingCompatibility control property, if this setting is set to 3.5, the default rendering is a table
, if this value is 4.0, the default rendering mode is a list ul
. You can change this setting globally in the web.config file:
<system.web>
<pages controlRenderingCompatibilityVersion="4.0"/>
</system.web>
Table. Renders as a table
List. Renders as a list
Since you are using the .Net Framework 3.5, probably the best way to accomplish this is to use Control Adapters
Basically the adapters work on a specific control, and in the adapter you can update the rendering of the target control, in this case the Menu
control
I have not created a control adapter, so I cannot give you further information other than pointing you in the right direction, googling I found this article which seems promising:
http://msdn.microsoft.com/en-us/magazine/cc163543.aspx
Upvotes: 1