By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,264 Members | 1,700 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,264 IT Pros & Developers. It's quick & easy.

Learnig to Build a Tree View Control

P: n/a
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.

Nov 19 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
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.

"dwok" <de***@wubbafish.net> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
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.

Nov 19 '05 #2

P: n/a
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

Nov 19 '05 #3

P: n/a
spoken like a true MVP

Nov 19 '05 #4

P: n/a
Did you intend for this to be helpful?

Nov 19 '05 #5

P: n/a
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)

"dwok" <de***@wubbafish.net> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
| Did you intend for this to be helpful?
|
Nov 19 '05 #6

P: n/a
Hello Dwok,
Check out the control gallery at ww.asp.net:
It has an entire section dedicated to treeviews:
http://www.asp.net/ControlGallery/de...=28&tabindex=2

I personally have used this one with success (it's free):
http://www.asp.net/ControlGallery/Co...014&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.
"dwok" wrote:
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.

Nov 19 '05 #7

P: n/a
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

"Tim Stall" wrote:
Hello Dwok,
Check out the control gallery at ww.asp.net:
It has an entire section dedicated to treeviews:
http://www.asp.net/ControlGallery/de...=28&tabindex=2

I personally have used this one with success (it's free):
http://www.asp.net/ControlGallery/Co...014&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.
"dwok" wrote:
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.

Nov 19 '05 #8

P: n/a
How do you think I came to become one? ;-)

--
HTH,

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

"re****@community.nospam" <ma**********@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
spoken like a true MVP

Nov 19 '05 #9

P: n/a
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.

"dwok" <de***@wubbafish.net> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Did you intend for this to be helpful?

Nov 19 '05 #10

P: n/a
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.

Nov 19 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.