LoadOnDemand is a very useful feature when you have treeviews with large number of treenodes. It makes the treeview not to load all treenodes at once, but to load only the treenodes of the currently expanding branch and thus saving the CPU time. LoadOnDemand is actually not a built-in feature or a property of Telerik RadTreeView, but rather a model for operating the treeview in order to support huge number of nodes. This approach works in the following way:
1. Set Initial Request
| |
Copy Code |
|
Page.PostBack == False |
2. Load your DataSource (SQL, XML, etc) in the initial request to the page and store it in the Cache.
3. In the initial request add only the root nodes to the tree. Mark the nodes that have child nodes with the ExpandMode.ServerSide attribute.
| |
Copy Code |
|
... node.ExpandMode = ExpandMode.ServerSide; ... |
4. Hook the NodeExpand server-event. The NodeClicked property of the RadTreeNodeEventArgs contains the instance of the expanded node.
PostBack the event (NodeExpand event fires). Below is a sample NodeExpand server-side event handler that gets the node clicked and loads it with its children (assuming you have LoadChildNodes(RadTreeNode node) method that takes care of that per your requirements):
| |
Copy Code |
|
private void RadTree1_NodeExpand(object o, Telerik.WebControls.RadTreeNodeEventArgs e) { ... RadTreeNode nodeClicked = e.NodeClicked; nodeClicked.Nodes.Clear(); LoadChildNodes(nodeClicked); ... } |
5. Load your DataSource from the Cache.
6. Clear child nodes of the node, if any. Add all child nodes of this node to its Nodes collection, setting the ExpandMode.ServerSide attribute for nodes that have children.
You can find more information and detailed code examples in the "Load On Demand (Sql)" and "Load On Demand (Xml)" from the Quick-Start framework (Start Menu -> Programs -> Telerik -> Telerik RadTreeView v6.0 ->ASP.NET 2.X -> Telerik RadTreeView v6.0 Live Examples).
See Also