Home - Forums-.NET - FlyTreeView (ASP.NET) - PopulateOnDemand and PopulateNodes Event for datasource

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

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

PopulateOnDemand and PopulateNodes Event for datasource
Link Posted: 30-Jan-2007 02:36
Please can youprovide a suitable code fragment to enable node PopulateOnDemand to function when the treeview control (ASP.NET 2) is bound to a runtime database datatasource
Link Posted: 30-Jan-2007 04:30
There's no difference on how you add nodes to treeview.

Initially you add root nodes (or even with some child nodes). You'll need to set PopulateOnDemand (probably in NodeDataBound event for data binding) to true for leaf nodes.

For the PopulateNode handler you need to set data source for e.Node.ChildNodes.DataSource = youData;
and call e.Node.ChildNodes.DataBind()
This way you can bind a particular (requested on demand from client) branch of nodes.
Link Posted: 31-Jan-2007 03:39
I seem to be missing a trick with this one, how can I only return the Root and 1st level child nodes from the dataset?  Currently I can only databind the whole 5000 nodes to the control, this is then rendered all in one go.  I do not wish to have to hard code nodes if possible as the entire tree structure can change dynamically.

Any code would be most helpful
Link Posted: 31-Jan-2007 06:34
What type of dataset do you use?
Do you use hierarchical dataset or plain one (and specify parentID and ID fields in this case)?

Probably you need to filter dataset somehow so that you have the only required branch for the requested nodes (for particular expanded node).
Link Posted: 31-Jan-2007 21:52
I'm using a tabular dataset parsed through the ConvertTabularDataToHierarchical function, the code used is below:

In the page load function:
          hierarchicalData = NineRays.WebControls.FlyTreeView.ConvertTabularDataToHierarchical(dbread, \"CompleteLCNTreeMk3\", \"ChildID\", \"ParentID\")

            FlyTreeView1.DataSource = hierarchicalData
            FlyTreeView1.DataBind()


In node_databound:
        
Dim val1 As String = DataBinder.Eval(e.Node.DataItem, \"ChildID\")
        Dim val2 As String = DataBinder.Eval(e.Node.DataItem, \"ChildName\")

        e.Node.Text = String.Format(\"{0}: {1}\", val1, val2)
        e.Node.PopulateNodesOnDemand = True


In PopulateNodes

        e.Node.ChildNodes.DataSource = hierarchicalData
        e.Node.ChildNodes.DataBind()
        e.Node.PopulateNodesOnDemand = True


I've tried filtering the dataset at source so it only returned the root & 1st level children, and then tried accessing a seperate 'complete' dataset to populate further children, however this didn't return any data.  Is there a way to filter the hierarchical Dataset generated?
Link Posted: 01-Feb-2007 00:58
There's no built-in functionality to filter data sources.

Anyway I think there is a possible solution to filter original DataTable.
In this case, you'll need to remove from the datatable all original root nodes rows (having ChildID=ParentID or ParentID=null) and set ParentID of node rows having ParentID=expandedNodeRecordChildID to null (or DBNull)

Then you'll need to transform datatable into hierarchical representation and call DataBind().