Skip to main content
Tab

MenuItem.TextTemplate Property

Gets or sets a template used for displaying the text content of the current menu item.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.2.dll

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 menu item’s text content.

Remarks

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

Note that any style settings defined for the menu item via specific properties (such as the ASPxMenuBase.ItemStyle or ASPxMenuBase.SubMenuItemStyle, etc) are still in effect for the menu item whose content is specified through using the TextTemplate property.

In order to define the common text content for all menu items within a menu control, the menu’s ASPxMenuBase.ItemTextTemplate property can be used. A template for the client regions of submenus can be specified via the ASPxMenuBase.SubMenuTemplate or MenuItem.SubMenuTemplate property.

Note

Once a template defined via the TextTemplate property is created within a tab control, it is instantiated within a container object of the MenuItemTemplateContainer type. This container object exposes a set of specific properties to which the template’s child controls can be bound.

Note

An TextTemplate cannot contain another menu control.

Example

This example illustrates how to create a TextTemplate and assign it to MenuItem at runtime.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using DevExpress.Web.ASPxEditors;
using System.Web.UI;
using System.Drawing;


public partial class _Default : System.Web.UI.Page {
    protected void Page_Load (object sender, EventArgs e) {

    }
    protected void ASPxMenu2_ItemDataBound (object source, DevExpress.Web.ASPxMenu.MenuItemEventArgs e) {
        SiteMapNode node = e.Item.DataItem as SiteMapNode;
        if (node != null) {
            e.Item.TextTemplate = new MenuItemTemplate(node);
        }
    }

    class MenuItemTemplate : ITemplate {
        SiteMapNode node;

        public MenuItemTemplate (SiteMapNode node) {
            this.node = node;
        }

        public void InstantiateIn (Control container) {
            ASPxLabel lb = new ASPxLabel();
            lb.Text = node.Title;
            container.Controls.Add(lb);

            if (node["description"] == null)
                return;

            System.Web.UI.HtmlControls.HtmlGenericControl dynBR = new System.Web.UI.HtmlControls.HtmlGenericControl("BR");
            container.Controls.Add(dynBR);

            ASPxHyperLink link = new ASPxHyperLink();
            link.NavigateUrl = node.Url;
            link.Text = node["description"];
            link.ForeColor = Color.Blue;
            container.Controls.Add(link);


        }
    }
}
See Also