loading a treeview in asp.net

E

Erick

Can some one help me with loading a treeview in asp.net 2.0

I have a table with records and each record has a column that has a
value which points to the parents record id.
All examples i have seen on the internet load the top node and then
call the database again once a node is clicked.

I would like to load the entire table into a tree view.
I'd rather not have to go through using an xml file.

Does anyone have the code for filling the tree view completely?
Do the records in the referencing table need to be in a specified
sequence ?
Do you need to use treeview1.findnode. Is this a slow method and how
is it used ?

thanks.
 
J

John Padilla

Eric,

i use the tree view as a menu system in my Asp.Net apps.

In my system i have a heiarchy, a bunch of parent Nodes (Categories) with
child nodes and it all comes from a database. The menu child items redirect
uses to the proper pages.

Example:

dsYourData is a DataSet. You cant use foreach with a DataTable so if you are
using DataTable or any iEnumerable type then use for(i=0;
YourEnumerableObject.Count, i++) {}

foreach (DataRow curParentRow in dsYourData.Tables[0].Rows)
{
SetNewParentNodeNode((string)curRow["ParentName"],
(string)curRow["parentId"]);
}

private void SetNewParentNodeNode(string ParentName, string ParentId)
{
TreeNode ParentNode = new TreeNode();
ParentNode .Text = ParentName;
ParentNode .Value = "ParentId";

tvYourTreeView.Nodes.Add(ParentNode );
}

Hope this helps!
 

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,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top