Menu - Client-side Templates

  • Politics
  • Sports
  • Events
Isolate this demo as a stand-alone application
  • About this demo
  • C#
  • VB

RadMenu now supports client templates. The templates are declared in the ClientItemTemplate 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 items loaded through web service. To apply a client template to an arbitrary item, you have to call the bindTemplate() function on that item:

    function addItem(itemText) 
        var item = new Telerik.Web.UI.RadTreeItem();
        var menu = $find('<%=RadMenu1.ClientID%>'); 
You can also assign a specific template to individual items on the client:
    function setTemplate(item) 
        item.set_clientTemplate("Item Text: #= Text #");
  • DefaultCS.aspx
  • DefaultCS.aspx.cs
  • styles.css
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="Menu.Examples.Functionality.ClientTemplates.DefaultCS" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
<html xmlns=''>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
    <link rel="stylesheet" href="styles.css" type="text/css" />

    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />

    <div class="demo-container size-narrow">
        <telerik:RadMenu RenderMode="Lightweight" runat="server" ID="RadMenu1" DataSourceID="SqlDataSource1" DataFieldID="id"
            DataFieldParentID="parentId" DataTextField="Text" DataValueField="id">
                <img alt="#= Text #" src="Images/#= Text #.png" />
                <span class="templateText">#= Text #</span>
                <telerik:RadMenuItemBinding Depth="0" ExpandMode="WebService" />
            <WebServiceSettings Path="Links.asmx" Method="GetMenuLinks" />
    <asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
        SelectCommand="SELECT * FROM Links WHERE parentId IS NULL" />


Find Assistance

Help Us Improve

Was this example helpful?