SiteMapPath.RootNodeTemplate Property

Gets or sets a control template to use for the root node of a site navigation path.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public virtual ITemplate RootNodeTemplate { get; set; }

Property Value

Type: System.Web.UI.ITemplate
An ITemplate object that implements the InstantiateIn method, to render custom content for the root node of a navigation path.

Set the RootNodeTemplate to an ITemplate object to use an Image control or some other control, such as a Label as the root node's user interface element instead of a string.

If the RootNodeTemplate property is set, the template overrides both the root navigation node text displayed and any RootNodeStyle applied to it. The template also overrides the CurrentNodeTemplate and CurrentNodeStyle properties if the root page is the currently displayed page.

You can declaratively set the RootNodeTemplate property to any Web server control, and the ASP.NET infrastructure performs the necessary steps to wrap the Web server control as an ITemplate. However, Web server controls do not implement the ITemplate interface; therefore, when you work with the ITemplate properties programmatically, you must write an ITemplate wrapper for any template code. Then, the RootNodeTemplate property is set to an instance of the ITemplate wrapper.

The following code example demonstrates how to programmatically define a class that implements the ITemplate interface to wrap an Image control. Then, the RootNodeTemplate property is set to an instance of the class.

<%@ Page language="c#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<script runat="server">
    private void Page_Load(object sender, System.EventArgs e)
        // Create the SiteMapPath control.
        SiteMapPath navpath = new SiteMapPath();

        // Make the root node look unique.
        // The Image that you can use in your Web page is an
        // instance of the WebControls.Image class, not the
        // Drawing.Image class.
        System.Web.UI.WebControls.Image rootNodeImage =
            new System.Web.UI.WebControls.Image();
        rootNodeImage.ImageUrl = "myimage.jpg";
        ImageTemplate rootNodeImageTemplate = new ImageTemplate();
        rootNodeImageTemplate.MyImage = rootNodeImage;
        navpath.RootNodeTemplate = rootNodeImageTemplate;

        // Make the current node look unique.
        Style currentNodeStyle = new Style();
        navpath.CurrentNodeStyle.ForeColor = System.Drawing.Color.AliceBlue;
        navpath.CurrentNodeStyle.BackColor = System.Drawing.Color.Bisque;

        // Set the path separator to be something other
        // than the default.
        navpath.PathSeparator = "::";


    // A simple Template class to wrap an image.
    public class ImageTemplate : ITemplate
        private System.Web.UI.WebControls.Image myImage;
        public System.Web.UI.WebControls.Image MyImage
                return myImage;
                myImage = value;
        public void InstantiateIn(Control container)

<html xmlns="" >
  <head runat="server">
    <title>About Our Company</title>
    <form id="Form1" method="post" runat="server">

      <asp:PlaceHolder id="PlaceHolder1" runat="server"></asp:PlaceHolder>

      <h1>About Our Company</h1>

      <p>Our company was founded in 1886.</p>

      <p>We use only the finest ingredients, organically grown fruits, and
      natural spices in our homemade pies. We use no artificial preservatives
      or coloring agents. We would not have it any other way!</p>


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft