Export (0) Print
Expand All

SiteMapPath Constructor

Note: This constructor is new in the .NET Framework version 2.0.

Initializes a new instance of the SiteMapPath class.

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

public SiteMapPath ()
public SiteMapPath ()
public function SiteMapPath ()

Use this constructor to create and initialize a new instance of the SiteMapPath class. To dynamically add a SiteMapPath control to a page, create a new SiteMapPath object, set its properties, and then add it to the Control.Controls collection of a container control such as PlaceHolder.

The following code example demonstrates how to use the SiteMapPath constructor to add a SiteMapPath control to a page. For the example to work, you need to add an image to your root directory and change the image name in the example code from "myimage.jpg" to the name of your image file.

<%@ Page language="c#"%>
<!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.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 = "::";

        PlaceHolder1.Controls.Add(navpath);
    }


    // 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
        {
            get
            {
                return myImage;
            }
            set
            {
                myImage = value;
            }
        }
        public void InstantiateIn(Control container)
        {
            container.Controls.Add(MyImage);
        }
    }
</SCRIPT>

<HTML>
  <body MS_POSITIONING="GridLayout">
    <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>

    </form>
  </body>
</HTML>

<%@ 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>
  <body MS_POSITIONING="GridLayout">
    <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 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft