SiteMapPath.RootNodeTemplate Property
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.
<%@ 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>