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
Solved

Reading Data into TreeView from SQL Table

Posted on 2007-03-21
6
232 Views
Last Modified: 2010-04-16
Hi all,
I have a table with Zip Codes in it.  From this, I want to create a tree view of data.  However, I need to drill down and give people options on what they are allowed to select.  My datatable contains 4 columns:
State, County, City, Zip
I want to create a parent node at their level (State, County, or City).  and then give them the ability to select anything below them
for instance, I am at a county level.  In the tree view, I want to see my county, then all the cities in my county and then all my zip codes in my city.  So my tree would look like this:
County
|-City1
|--Zip1C1
|--Zip2C1
|-City2
|--Zip1C2
|-City3
|--Zip1C3
|--Zip2C3
|--Zip3C3

But, if I am at the state level, I want to be able to have the state as the parent, and then each county under that, and each city....

How can I separate out the parent (I already know what level they are at) and then create all the children.  This is all in 1 table.
I do have the table set at the correct level for data reading (meaning I do a select * from table where state='mystate' if I am at state level, select * from table where state='mystate' and county='mycounty' for county level, and so on.
0
Comment
Question by:ericlockshine
  • 2
  • 2
  • 2
6 Comments
 
LVL 12

Expert Comment

by:craskin
ID: 18766347
SELECT state FROM myTable GROUP ON state
0
 
LVL 12

Expert Comment

by:craskin
ID: 18766355
you can also do

SELECT DISTINCT state FROM myTable
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 18768197
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:ericlockshine
ID: 18771149
craskin:
I already have the data in one table from the database.  That is not what I was asking but thanks for the help.
emoreau:  Do you know how to create relationships out of the same table?  Do I have to retrieve the data in a different way to allow for the tree to be built?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 18771624
see the code in the "Filling the Treeview" section. You need to have 2 datatables (1 for city and one for zips in your case) and establish a DataRelation between those 2 DataTables.
0
 

Author Comment

by:ericlockshine
ID: 18779549
Thanks emoreau:
I was able to populate the nodes and create the relationships.  What I had to do was this:  For each level that I was at, select the appropriate information from my database.  So, for each level I need to select one more level.  Your example gave me the information that I needed to program the tree and to decide how to select the information from the database.

I have All States, Counties, Cities and Zip Codes to load.  For each level, they get access at their level: Cities get city level and zip level, Counties get county level, city level and zip level.  Once I figured out how to get this out of the database, the rest was easy.

Thanks for your help!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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