Learnig to Build a Tree View Control

D

dwok

Does anyone know of a good article that discusses creating a "Tree
View" control in ASP.NET? Or perhaps a Tree View Control that comes
with source code? I have come across a lot of tree controls for ASP.NET
however most of them are already compiled and don't come with source
code. I am really just looking for an example on how to create my own
Tree Control. Thanks a bunch.
 
K

Kevin Spencer

Creating a Tree View Control is the same as creating or designing an
application. You enumerate a set of requirements, look at the available
tools and technologies, figure out what will satisfy your requirements, and
come up with a plan. Rather than looking at examples of how other people
soved the problem, why not look at this as an opportunity to practice your
analysis and design skills?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
R

recoil

It is extremely simple.
While I do not have the time to go into greater detail regarding how it
is the topics you should be familiar with already are
Using the Viewstate to store your own variables.
Creating custom classes that are serializable and deserialiazable
and Recursiveness

if i were you i would build a custom class that implements ICollection.
This will be referred to as your NodeCollection from here on out.
You will have another custom class. This will be referred to as your
Node from here on out.
Both have to be marked as Serializable. Look up this Attribute in the
msdn library.
For speed skae you should implement ISerializable and implement the
special constructor and add and retrieve all of your variables
manually. This requires more code but offers a significate performance
boost as it doesnot have to use reflection when serializaing and
deserializing.

Your TreeNode will have a property that is of the type NodeCollection.
you will override LoadViewState and SaveViewState and by simply adding
your Tree's Node Collection to the viewstate everything is serialized
automatically and deserialized. All you have to do is add and retrieve
it from the Viewstate.

Rendering is simply a matter of Recursive ness.
foreach (treenode in treenodecollection)
{
render node
callself(treenode.Nodes)
}



Hope this is helpful in any way
 
B

bruce barker

if you goto the book store and look at the javascript/html section, you
should find lots of material on this and other html ui components. in the
asp.net seciton you may even find .net implimentations.

if you go to any website that has a tree control you like, with the browser
view source to see the code. firefox has really good tools for this.

-- bruce (sqlwork.com)



| Did you intend for this to be helpful?
|
 
G

Guest

Hello Dwok,
Check out the control gallery at ww.asp.net:
It has an entire section dedicated to treeviews:
http://www.asp.net/ControlGallery/default.aspx?Category=28&tabindex=2

I personally have used this one with success (it's free):
http://www.asp.net/ControlGallery/ControlDetail.aspx?Control=1014&tabindex=2

Some tips to get you started:
1 - Think out your requirements. Do the nodes need to be multi-line? Should
they be able to contain any HTML (images, tables, etc...) or just single
literal strings or links.
2 - How will you set the data? With an xml file, from a DataTable (with
recursive columns), programatically?
3 - Figure out your javascript/html needs: (1) how to children collapsed
(hidden), (2) how to persist across postback. Look at the view-source for
other successful treeviews.
 
G

Guest

Hi,

For building the treeview control u should decide on which data source u
r going to use to populate the tree view. i have developed a treeview control
in which the nodes and all the info. required for the elements in the tree
view control are in XML files. then using XML dom we can parse through that
and develop the tree view control.
for more info. regarding the tree view control u can look into the
june2004 edition of MSDN Magazine.

Regards,
Sundararajan.S
 
K

Kevin Spencer

How do you think I came to become one? ;-)

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
K

Kevin Spencer

If you're replying to me, the answer would be "yes, doubtless more helpful
than you realize."

Which is more helpful - to feed a man a fish, or to teach a man to fish?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
D

dwok

Thank you for all the replies. A lot of people suggested on how to
start planning for a TreeView control but what I am really looking for
is an example. As I see it there are many things to consider when
developing an ASP.NET TreeView control.

1. client-side vs. server-side interaction
2. datasource (XML, Dataset, Collection, etc..)
3. Node properties
4. Load entire tree vs. single node

These are all things that I think would be made much clearer to me if
I had an example to look at. There are many great treeview controls out
there for ASP.NET however I would like to be able to look at the source
code in order to understand how they are created.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,829
Latest member
PIXThurman

Latest Threads

Top