New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Client Templates

  • Group A
  • Group B
  • Group C
  • Group D
RadTreeView now supports client templates. The templates are declared in the ClientNodeTemplate tag and support the following expressions for evaluating code:
  • #= ... # - Data - Evaluates the Javascript code expression or a string property from the data item and outputs the result in the template.
  • # ... # - Code - Evaluates the JavaScript code expression inside. Does not output value.
  • #: ... # - HTML-encode - Same as the data expression, but HTML-encodes the result.
The templates are applied automatically to all nodes loaded through web service. To apply a client template to an arbitrary node, you have to call the bindTemplate() function on that node:
    function addNode(nodeText) 
    {
        var node = new Telerik.Web.UI.RadTreeNode();
        var tree = $find('<%=RadTreeView1.ClientID%>'); 
        node.set_text(nodeText);
        node.bindTemplate();
        tree.get_nodes().add(node);
    }
		
You can also assign a specific template to individual nodes on the client:
    function setTemplate(node) 
    {
        node.set_clientTemplate("Node Text: #= Text #");
        node.bindTemplate();
    }
		
  • DefaultCS.aspx
  • DefaultCS.aspx.cs
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="TreeView.Examples.Functionality.ClientTemplates.DefaultCS" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <div class="demo-container size-thin">
        <telerik:RadTreeView RenderMode="Lightweight" ID="RadTreeView1"  runat="server">
            <ClientNodeTemplate>
            <img src="#= Value #" alt="#= Value #" />
            <span>#= Text #</span>
            </ClientNodeTemplate>
            <Nodes>
                <telerik:RadTreeNode Text="Group A" Value="A" ExpandMode="WebService">
                </telerik:RadTreeNode>
                <telerik:RadTreeNode Text="Group B" Value="B" ExpandMode="WebService">
                </telerik:RadTreeNode>
                <telerik:RadTreeNode Text="Group C" Value="C" ExpandMode="WebService">
                </telerik:RadTreeNode>
                <telerik:RadTreeNode Text="Group D" Value="D" ExpandMode="WebService">
                </telerik:RadTreeNode>
            </Nodes>
            <WebServiceSettings Path="defaultcs.aspx" Method="GetTeams">
            </WebServiceSettings>
        </telerik:RadTreeView>
    </div>
    </form>
</body>
</html>

Support & Learning Resources

Find Assistance