Skip to main content
Tab

TreeViewNode.TextTemplate Property

Gets or sets a template used for displaying the text content of the particular node.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.1.dll

NuGet Package: DevExpress.Web

Declaration

[DefaultValue(null)]
public virtual ITemplate TextTemplate { get; set; }

Property Value

Type Default Description
ITemplate null

An object supporting the ITemplate interface which contains the template used for displaying the node’s text content.

Remarks

Use the TextTemplate property to control the text content of the particular node. The template defined using this property replaces the text content of an individual node - in particular, the node’s text specified.

Note that any style settings defined for the node via specific properties (such as the TreeViewStyles.Node) are still in effect for the node whose content is specified through using the TextTemplate property.

In order to define a common text content for all nodes within an ASPxTreeView control, the ASPxTreeView.NodeTextTemplate property can be used.

Note

Once a template defined by this property is created, it is instantiated within a container represented by the TreeViewNodeTemplateContainer class. The TreeViewNodeTemplateContainer class implements a set of properties which can be useful when designing a template and binding the controls composing this template to data.

Example

This example illustrates how to create a template and assign it to TreeViewNode at runtime conditionally. As ASPxTreeView is bound to a datasource in this example, it is necessary to handle the ASPxTreeView.DataBound event to refer to a node.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxTreeView" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>How to create TreeViewNode.TextTemplate at runtime</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <dx:ASPxTreeView ID="treeView" runat="server" DataSourceID="XmlDataSource1" AllowSelectNode="true"
            OnNodeDataBound="treeView_NodeDataBound" TextField="Title" 
            ImageUrlField="NodeTypeImage">
            <Images>
                <NodeImage Width="16px" Height="16px">
                </NodeImage>
            </Images>
            <Styles>
                <NodeImage Paddings-PaddingTop="3px">
                </NodeImage>
            </Styles>
        </dx:ASPxTreeView>
        <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/HelpNav.xml"
            XPath="/namespace/*"></asp:XmlDataSource>
    </div>
    </form>
</body>
</html>
See Also