views:

459

answers:

3

I need to populate an ASP.NET menu control with hierarchical structure with menu items that can be constantly changed, from a database (categories with n levels of sub categories).

There are some approaches for that and I would like to hear which one is the most efficient one.

I have those in mind:

  1. Retrieving data from database and converting it to xml then transforming it with customized XSLT file and binding it to Menu control
  2. Retrieving data from database and while looping through (recursive), inserting menu items and children to the menu control
  3. SQL Site Map Provider (thanks to Made4Print)
  4. Something else?
+1  A: 

If you want to do this, I would definitely recommend option 2, since it contains one level of transformation less than option 1. If you already loop through the menu items and their hiearchies, you might as well build up the menu items and subitems directly - I don't see any big benefit from taking a detour over XML and then through XSLT into a menu structure, really.

Marc

PS: Option 3 (the SQL Sitemap provider) also sounds like a really good idea, if the site map structure and options are good enough for you (they usually should be). I would probably try that option first, and go from there.

marc_s
My only concern is efficiency, menu items can be constantly changed.Menu items removes or moved(with it children) between parents and etc.So this will require to rebuild menu structure.
markiz
Yes sure - but that also is true if you then convert the changed structure to XML first and using XSLT into the actual menu structure - I don't think you win anything by going this route.
marc_s
+1  A: 

I agree with Marc. You could then package everything inside a server-control for reusability. Converting everything into XML and then using XSLT to somehow "convert" it back seems an overhead to me.

Juri
+3  A: 

The ASP.NET Menu Control can use a .SiteMap file through a SiteMapDataSource.

You can implement your own SiteMapProvider, this way you can have your SiteMap heirarchy within your database and wireup the same components making things more dyanamic.

Here is an example: http://weblogs.asp.net/scottgu/archive/2006/01/11/435108.aspx

HTH

Mark Redman
This is also an option. Don't know what is best :(
markiz
I guess the best is to try one solution and see if it works to your satisfaction, and if not, or if you have enough time, try a second one and compare the results; both the amount of work for you to create and maintain your menu structures, as well as the runtime behavior
marc_s
I've already implemented the 1 and 2, how can i compare them?
markiz
Measure execution speed, measure how easy or hard it is for you to make changes etc.
marc_s