Home - Forums-.NET - FlyTreeView (ASP.NET) - How to implement loading on demand

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

How to implement loading on demand
Link Posted: 02-Nov-2007 03:36
Hi,

how do I implement loading of treenodes when expanding the tree, means on demand. Is it needed to use AJAX?

Where can I find a documentation for this or other issues?

Thank you in advance!
Link Posted: 02-Nov-2007 04:23
You can simply open populate-on-demand demo and its source code.

Actually, all you need is to set
node.PopulateOnDemand = true;

And handle flytreeview.PopulateNode event.
Link Posted: 02-Nov-2007 05:15
Thank you, sounds to be easy .. populate-on-demand demo means the ClientEvent-demo?
Link Posted: 02-Nov-2007 06:02
Oke .. this works now, but I got another question:

After modifying an object, I want to reload the whole tree and expand it as the path of the modified object defines. I implemented an own method which does not work now (with loading the nodes on demand) anymore.

What should I make different or does a method already exist, which expands the tree by a given path?

Here is the code of the method:
protected void ExpandTree(FlyTreeView tree, string[] path)
        {
            FlyTreeNodeCollection collection;
            FlyTreeNode node = new FlyTreeNode();
            for (int i = 0; i < path.Length; i++)
            {
                if (i == 0)
                {
                    collection = tree.Nodes.FindByValue(path[0], false);
                    if(collection.Count <= 0)
                        break;

                    node = collection[0];
                    node.Expanded = true;
                    tree.
                }
                else
                {
                    collection = node.ChildNodes.FindByValue(path[i], false);
                    if (collection.Count <= 0)
                        break;

                    node = collection[0];
                    node.Expanded = true;
                }
            }
        }
Link Posted: 02-Nov-2007 06:41
You just need to find node by path.
(You can use Find(predicate) method)
and expand all node's parents.
Link Posted: 02-Nov-2007 08:26
Sorry, this was misunderstanding. I \"reload\" the tree by requesting the complete tree-page from another page (I use frames). So the tree is completly initialized new, I do not have access to the node-object to which I have to navigate to.

Because of my loading-on-demand, the childnodes of the rootnodes are not instantiated yet. Is there a possibility to build the tree up to the requested node automatically in my cs-page before the page will be displayed? In my method, I set node.Expand() on the first level, but of course there is nothing to expand ..
Link Posted: 02-Nov-2007 08:43
Sorry, I do not completely understand your idea.

Do you need to expand nodes at some server side?

If you're using populate-on-demand, then you need to find first node by value, expand it, call treeview.PopulateExpandedNodes(), then find next node  though its children, then expand it and again call PopulateExpandedNodes() and so on recursively.

You can also create a web project with simple implementation of what you need to achieve and upload it to ftp://download.9rays.net/9r_incoming/ . So I can modify locally to help you.