Creating a Databases Menu with ASP.NET, JQuery and Suckerfish

I am trying to create a menu from a table using cckerfish css and JQuery menu. I use this as my link: Suckerfish Menu with ASP.NET and JQuery , and I have a manual link to work with (just like in the article).

In cases where problems arise, I write a recursive function to retrieve menu items from the database and create new menu items in the correct hierarchy. My database table looks like this:

Table menu


MenuID ParentID Link Text

The idea is that if an element is a parent level element, the MenuID and ParentID are the same, if it is a child, it will have that parent's MenuID in the ParentID field. I need to create a function that can go through and find all children for parents (there may be multiple levels) and replace it with the following entries:

        Dim Foo As New MenuItem("#", "Foo", Me)
        Items.Add(Foo)
        Foo.Items.Add(New MenuItem("#", "1", Me))
        Foo.Items.Add(New MenuItem("#", "2", Me))
        Foo.Items.Add(New MenuItem("#", "3", Me))
        Foo.Items.Add(New MenuItem("#", "4", Me))

      

I can change the structure of the database table if needed and basically do something else to make it happen.

Thanks for any input, he really appreciates.

0


source to share


1 answer


This method of representing hierarchical data is easy for humans to understand, but difficult to extract data from because it requires recursion to complete the hierarchy. Some SQL variants have commands that will do this for you, but this is what happens behind the scenes.



I suggest you read More Trees and Hierarchies in SQL and restructure your schema with the materialized path method he explains. Easy to query and scale very well.

+2


source







All Articles