Solved

Display a parent-child tree in ASP.NET (VB)

Posted on 2011-02-17
4
744 Views
Last Modified: 2012-05-11
Hi,

I have a category table that effectively has CategoryID, CategoryName and ParentID.  In the table, the 3 top-level categories have a parent of 0 and all remaining categories are children of the top 3.

There is also a presenter table and a presentercategory table that bridges presenters with categories.  It's fields are PresentercatID(PK), CategoryID and PresenterID.

I am now required to display these categories in an ASP.NET (vb) page such that the categories are displayed alphabetically and that the parent/child relationships are exposed through progressive UL-LI HTML tags like this:

<ul>
    <li>grandparent</li>
    <ul>
        <li>parent></li>
        <ul>
            <li>child</li>
        </ul>
        <li>Other parent</li>
    <ul>
    <li>Other grandparent</li>
</ul>

Open in new window


What would be the best approach to doing this?

Thanks in advance!

Best,

Paul
0
Comment
Question by:pmodiano1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 3

Expert Comment

by:chrisrbloom
ID: 34919409
I think I can help, but your table structure is a little confusing.  Can you please clarify?

Are there 3 tables?  Categories, Presenters and PresenterCategories?

I'm confused what the PresenterCategories table would be used for (one to many between the other 2 should work?)

0
 

Author Comment

by:pmodiano1
ID: 34919525
Hi Chris,

There are 3 tables because there is a many-to-one relationship between categories and presenters (any presenter may have several categories).  Take a look at the attached image.

 er diagram
Let me know.

Thanks,

Paul.
0
 
LVL 3

Accepted Solution

by:
chrisrbloom earned 500 total points
ID: 34919721
got it.  

OK, what you need to do is set up a couple of queries.

First, you need a query that will give you a list of all the presenterID's in the Presentercat table (distinct values).  Let's call this query qry_AllPresenters

Second, you need to set up a query that gives you all the categoryID's for a given presenter (something like "SELECT CategoryID from presentercat WHERE PresenterID = @PresenterID")  Let's call this query qry_PresenterCategories

I'm not sure what you are using (web page vb.net, VBA, etc so forgive me for not posting code, but I'll give you the idea here)

Set up a While Loop that iterates through the qry_AllPresenters.  While it's on each record, set up a nested loop  that iterates through qry_PresenterCategories WHERE @PresenterID = the current Presenter record you are on.

If you really want to do the <UL> you can append html code to a string value as you go, adding <UL's> and <LI> tags through the list for every record you get.

If you would rather, you can set up a TreeView Control (http://www.beansoftware.com/ASP.NET-Tutorials/Using-TreeView-Control.aspx) which would make this coding much simpler.



0
 

Author Closing Comment

by:pmodiano1
ID: 35700174
The actual solution was close but different
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question