Skip to main content
Tab

ASPxMenuBase.ItemTemplate Property

Gets or sets a common template used for displaying the content of all menu items within a menu control.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.2.dll

Declaration

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

Property Value

Type Default Description
ITemplate null

An object supporting the System.Web.UI.ITemplate interface which contains the template used for displaying the content of all menu items within a menu.

Remarks

Use the ItemTemplate property to define a common content for all menu items within a menu control (which can be either the ASPxMenu or ASPxPopupMenu). The template created using this property replaces the content of each menu item within the menu - in particular, the item’s image and the specified text.

Note that any style settings defined for the menu items via specific properties (such as the ASPxMenuBase.ItemStyle or ASPxMenuBase.SubMenuItemStyle, etc) are still in effect for the menu items whose contents are specified via the ItemTemplate property.

The content of an individual menu item can be defined using the item’s MenuItem.Template property. A template for the client regions of submenus can be specified via the ASPxMenuBase.SubMenuTemplate or MenuItem.SubMenuTemplate properties.

Note

Once a template defined via the ItemTemplate property is created within a 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 ItemTemplate cannot contain another menu control.

Example

This sample illustrates how to keep the NavigateUrl of the item if there is a control in the ItemTemplate of the ASPxMenu.

<dx:ASPxMenu ID="ASPxMenu1" runat="server" DataSourceID="ASPxSiteMapDataSource1"
    Orientation="Vertical" OnDataBound="ASPxMenu1_DataBound">
    <ItemTemplate>
        <dx:ASPxLabel ID="ASPxLabel1" runat="server" Text='<%#Container.Item.Text %>' 
                      Width="100px" Height="20px" Cursor="pointer">
        </dx:ASPxLabel>
    </ItemTemplate>
</dx:ASPxMenu>

</html>
protected void ASPxMenu1_DataBound(object sender, EventArgs e) {
    string url = "";
    for (int i = 0; i < ASPxMenu1.Items.Count; i++) {

        url = ASPxMenu1.Items[i].NavigateUrl;
        ASPxLabel lab = ASPxMenu1.Items[i].FindControl("ASPxLabel1") as ASPxLabel;
        if (lab != null) {
            lab.ClientSideEvents.Click = "function(s,e){window.location = '" + url + "';}";

            switch (lab.Text) {
                case "Yahoo!": {
                        lab.BackColor = System.Drawing.Color.LightPink;
                        break;
                }
                case "MSN": {
                        lab.BackColor = System.Drawing.Color.LightSkyBlue;
                        break;
                }
                case "Google": {
                        lab.BackColor = System.Drawing.Color.LightSeaGreen;
                        break;
                }
            }
        }
    }
}
See Also