TreeView Part 1 - Populating the New TreeView Control from a Hierarchical Database Table
(Page 1 of 4 )
Though the title is a mouthful it succinctly describes what will prove to be the most common use of the new TreeView control shipping with ASP.Net 2.0. The control will be perfect for implementing hierarchical structures in a User Interface, and this tutorial will show you how to actually get the data into the control from a ‘parent-child’ database table.
Meet the TreeView – A Brief Introduction
Asp.Net is all about speed and ease-of-use. Microsoft has taken a look at the most common problems that face Web Programmers, and has given us pre-packaged classes to meet those problems with a quick, drag-and-drop solution. The TreeView control is a perfect example of this.
For many years Web Programmers have had to come up with complex programmatic solutions to create a simple hierarchical interface. This involved retrieving data from a database or XML file, and then wrapping our brains around complicated recursive functions that determine the structure, UI design, and event handling for what looks like a simple ‘tree’ structure. Needless to say, it’s a pain, and this led to many 3rd party components being created that you can ‘painlessly’ integrate into your application for a fee.
Thankfully, Microsoft has decided that this is a common enough requirement, that it should in fact be part of the .Net framework. At first, a similar object was available in the unsupported ‘Advanced IE Controls’ package. Of course, it was still flaky, and only worked with Internet Explorer. Now however, it has received a full induction into the .Net class library.
I have found this control to be quite powerful and sufficiently flexible to meet most web programming needs. I say "most" because there are a few limitations, which I’ll address the in Properties configuration section.
This article will explain how to get parent/child styled data into the TreeView Control from a database. Some common examples of this would be in a Content Management System or site map, to display the site structure. Another common use is creating an Organizational Chart, or employee list, which is the approach I’ll take. Alright, let’s do it!
Next: Step 1 – Drag ‘n Drop >>
More Database Articles
More By Justin Cook