Solved

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

Posted on 2011-02-17
4
745 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

627 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