Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-02-17
4
Medium Priority
?
750 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 1500 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

670 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