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)

[TemplateContainerAttribute(typeof(SiteMapNodeItem))] 
public:
virtual property ITemplate^ RootNodeTemplate {
	ITemplate^ get ();
	void set (ITemplate^ value);
}
/** @property */
public ITemplate get_RootNodeTemplate ()

/** @property */
public void set_RootNodeTemplate (ITemplate value)

public function get RootNodeTemplate () : ITemplate

public function set RootNodeTemplate (value : ITemplate)

Not applicable.

Property Value

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.

No code example is currently available or this language may not be supported.
<%@ Page language="VJ#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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.set_ImageUrl("myimage.jpg");

        ImageTemplate rootNodeImageTemplate = new ImageTemplate();

        rootNodeImageTemplate.set_myImage(rootNodeImage);
        navpath.set_RootNodeTemplate(rootNodeImageTemplate);

        // Make the current node look unique.
        Style currentNodeStyle = new Style();

        navpath.get_CurrentNodeStyle().set_ForeColor(System.Drawing.Color.get_AliceBlue());
        navpath.get_CurrentNodeStyle().set_BackColor(System.Drawing.Color.get_Bisque());

        // Set the path separator to be something other
        // than the default.
        navpath.set_PathSeparator("---->");
        PlaceHolder1.get_Controls().Add(navpath);
    }


    // A simple Template class to wrap an image.
    public class ImageTemplate implements ITemplate
    {
        private System.Web.UI.WebControls.Image myImage;
        public System.Web.UI.WebControls.Image get_myImage()
        {
            return myImage;
        }


        public void set_myImage(System.Web.UI.WebControls.Image value)
        {
            myImage = value;
        }


        public void InstantiateIn(Control container)
        {
            container.get_Controls().Add(myImage);
        }
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>About Our Company</title>
</head>
<body>
    <form id="Form1" method="post" runat="server">

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

      <h1>About Our Company</h1>

      <p>Grandma Fanny founded our company 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. Grandma Fanny would not have it any other way!</p>

    </form>
  </body>
</html>

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show: