select

TreeView / Load on Demand Modes

Rate this demo: Feedback
Run example in: C# VB.NET Change Skin:
Vista
  • BlackBlack
  • DefaultDefault
  • ForestForest
  • HayHay
  • Office2007Office2007
  • OutlookOutlook
  • SimpleSimple
  • SitefinitySitefinity
  • SunsetSunset
  • TelerikTelerik
  • VistaVista
  • Web20Web20
  • WebBlueWebBlue
  • Windows7Windows7
Configuration
  • Client-Side
    • Products
    • Purchase
    • Support
    • Community
    • Corporate
  • Server-Side
    • Products
    • Purchase
    • Support
    • Community
    • Corporate
  • Web Service
    • Products
    • Purchase
    • Support
    • Community
    • Corporate
  • Page Methods
    • Products
    • Purchase
    • Support
    • Community
    • Corporate

Example Source Code & Description

Instructions
Open in new window
  • The Load On Demand feature allows the developer to delay the population of RadTreeView and save HTML output thus improving performance. RadTreeView supports three different types of load on demand:

    • Client-Side
    • Server-Side
    • Web Service
    • Page Methods

    To use a specific load on demand mode you need to set the ExpandMode property of a RadTreeNode. When using Client-Side or Server-Side mode you need subscribe to the NodeExpand event and create the tree nodes. Here is a sample implementation:

    C#:
    protected void RadTreeView1_NodeExpand(object sender, RadTreeNodeEventArgs e)
    {
    	RadTreeNode onDemandNode = new RadTreeNode("Loaded on demand");
    	//Configure the node to populate on demand as well
    	onDemandNode.ExpandMode = TreeNodeExpandMode.ServerSideCallback;
    	//Add the node as a child of the currently expanded node
    	e.Node.Nodes.Add(onDemandNode);
    }
    
    VB.NET:
    Protected Sub RadTreeView1_NodeExpand(sender As Object, e As RadTreeNodeEventArgs)
    	Dim onDemandNode As New RadTreeNode("Loaded on demand")
    	'Configure the node to populate on demand as well
    	onDemandNode.ExpandMode = TreeNodeExpandMode.ServerSideCallback
    	'Add the node as a child of the currently expanded node
    	e.Node.Nodes.Add(onDemandNode)
    End Sub
    

    For Web-Service load on demand you need to populate the WebServiceSettings property of RadTreeView.

    <telerik:RadTreeView ID="RadTreeView1" runat="server">
        <WebServiceSettings Path="TreeViewWebService.asmx" Method="LoadNodes" />
    </telerik:RadTreeView>
    

    Then implement the method to return the nodes that are loaded on demand. Here is a sample implementation:

    C#
    [ScriptService]
    public class TreeViewWebService : WebService
    {
    	[WebMethod]
    	public RadTreeNodeData[] LoadNodes(RadTreeNodeData node, object context)
    	{
    		List<RadTreeNodeData> result = new List<RadTreeNodeData>();
    		RadTreeNodeData node = new RadTreeNodeData();
    		node.Text = "Loaded on demand";
    		node.ExpandMode = TreeNodeExpandMode.WebService;
            
    		return result.ToArray();
    	}
    }
    
    VB.NET
    <ScriptService> _
    Public Class TreeViewWebService
    	Inherits WebService
    	<WebMethod> _
    	Public Function LoadNodes(node As RadTreeNodeData, context As Object) As RadTreeNodeData()
    		Dim result As New List(Of RadTreeNodeData)()
    
    		Dim node As New RadTreeNodeData()
    		node.Text = "Loaded on demand"
    		node.ExpandMode = TreeNodeExpandMode.WebService
    
    		Return result.ToArray()
    	End Function
    End Class
    

    Page Methods load on demand mode is very similar to Web Service. You need to set the WebServiceSettings property and use set the ExpandMode property to WebService. Make sure your page method is static and is marked with the WebService attribute.

    <telerik:RadTreeView ID="RadTreeView1" runat="server">
        <WebServiceSettings Path="Default.aspx" Method="LoadNodes" />
    </telerik:RadTreeView>
    
    C#
    [WebMethod]
    public static RadTreeNodeData[] LoadNodes(RadTreeNodeData node, object context)
    {
    	List<RadTreeNodeData> result = new List<RadTreeNodeData>();
    	RadTreeNodeData node = new RadTreeNodeData();
    	node.Text = "Loaded on demand";
    	node.ExpandMode = TreeNodeExpandMode.WebService;
        
    	return result.ToArray();
    }
    
    VB.NET
    <WebMethod> _
    Public Shared Function LoadNodes(node As RadTreeNodeData, context As Object) As RadTreeNodeData()
    	Dim result As New List(Of RadTreeNodeData)()
    
    	Dim node As New RadTreeNodeData()
    	node.Text = "Loaded on demand"
    	node.ExpandMode = TreeNodeExpandMode.WebService
    
    	Return result.ToArray()
    End Function
    
Compatible with ASP.NET 2.0, 3.5 AJAX enabled Accessibility Verified!Valid XHTML 1.1! Optimized for Visual Studio 2005, 2008
Copyright 2002-2010 © Telerik. All right reserved  | 
Telerik Inc., 460 Totten Pond Rd, Suite 640, Waltham, MA 02451

www.telerik.com  |  Terms of Use  |  Contact Us