Solved

Reading Data into TreeView from SQL Table

Posted on 2007-03-21
6
229 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 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 18768197
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 69

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Is IHttpActionResult a promise pattern? 2 37
Problem to picture file 3 41
Jquery autocomplete 10 30
XAML: Layout 8 0
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now