In many of my projects I have had to generate non-binary trees using information from the database and then display them in a â€œtree-likeâ€ structure as shown below.
My algorithm is very simple and it makes use of Dan Vanderboomâ€™s excellent Generic Tree Collection but frankly Iâ€™m not satisfied with certain aspects of my algorithm. The main issue â€“ the data can never be retrieved in the same order as shown above from the database.
Now that we have a collection ready, we can generate the tree structure
Finally, I add the items to my drop-down control by calling
Letâ€™s have a look at the function
I know I could have used LINQ but many of my projects are running in .NET 2.0 so I had to go old-school! Iâ€™m looking forward to your valuable comments as to how YOU would do this and why your solution is more efficient than mine.
Iâ€™m pretty much sure many of you have encountered this error if you have been using Code blocks inside your ASP.NET master pages for example,
1: <img src='<%= Page.ResolveUrl("~/image/top-mnu-agents.jpg") %>' alt="Agents" name="agents"
2: width="109" height="42" border="0" id="agents" /></a>
1: function PreloadImages()
3: /*MM_preloadImages('<%= Page.ResolveUrl("~/image/top-mnu-property.jpg") %>',
4: '<%= Page.ResolveUrl("~/image/top-mnu-agents.jpg") %>',
5: '<%= Page.ResolveUrl("~/image/top-mnu-company.jpg") %>',
6: '<%= Page.ResolveUrl("~/image/top-mnu-contact.jpg") %>');*/
Is this going to work? Make a guess! No, its not! Bump! Even though the code block is inside a comment block! Howâ€™s that! If you are curious why, ask the guys at Microsoft 😉
The workaround to this problem is Data Biding Expressions. Milan Negovan has discussed this in greater detail in this article.