.NET Framework Class Library SiteMapPath Class Displays a set of text or image hyperlinks that enable users to more easily navigate a Web site, while taking a minimal amount of page space.

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

Syntax
Public Class SiteMapPath _
Inherits CompositeControl
public class SiteMapPath : CompositeControl
public ref class SiteMapPath : public CompositeControl
type SiteMapPath =
class
inherit CompositeControl
end
The SiteMapPath type exposes the following members.

Constructors
|
| Name | Description |
|---|
.gif) | SiteMapPath | Initializes a new instance of the SiteMapPath class. | Top

Methods
|
| Name | Description |
|---|
.gif) | AddAttributesToRender | Adds HTML attributes and styles that need to be rendered to the specified HtmlTextWriterTag. This method is used primarily by control developers. (Inherited from WebControl.) | .gif) | AddedControl | Called after a child control is added to the Controls collection of the Control object. (Inherited from Control.) | .gif) | AddParsedSubObject | Notifies the server control that an element, either XML or HTML, was parsed, and adds the element to the server control's ControlCollection object. (Inherited from Control.) | .gif) | ApplyStyle | Copies any nonblank elements of the specified style to the Web control, overwriting any existing style elements of the control. This method is primarily used by control developers. (Inherited from WebControl.) | .gif) | ApplyStyleSheetSkin | Applies the style properties defined in the page style sheet to the control. (Inherited from Control.) | .gif) | BuildProfileTree | Infrastructure. Gathers information about the server control and delivers it to the Trace property to be displayed when tracing is enabled for the page. (Inherited from Control.) | .gif) | ClearCachedClientID | Infrastructure. Sets the cached ClientID value to nullNothingnullptra null reference (Nothing in Visual Basic). (Inherited from Control.) | .gif) | ClearChildControlState | Deletes the control-state information for the server control's child controls. (Inherited from Control.) | .gif) | ClearChildState | Deletes the view-state and control-state information for all the server control's child controls. (Inherited from Control.) | .gif) | ClearChildViewState | Deletes the view-state information for all the server control's child controls. (Inherited from Control.) | .gif) | ClearEffectiveClientIDMode | Infrastructure. Sets the ClientIDMode property of the current control instance and of any child controls to Inherit. (Inherited from Control.) | .gif) | CopyBaseAttributes | Copies the properties not encapsulated by the Style object from the specified Web server control to the Web server control that this method is called from. This method is used primarily by control developers. (Inherited from WebControl.) | .gif) | CreateChildControls | Infrastructure. Clears the current child controls collection, and rebuilds it by calling the CreateControlHierarchy method. (Overrides Control..::.CreateChildControls()()().) | .gif) | CreateControlCollection | Creates a new ControlCollection object to hold the child controls (both literal and server) of the server control. (Inherited from Control.) | .gif) | CreateControlHierarchy | Examines the site map structure provided by the SiteMapProvider and builds a child controls collection based on the styles and templates defined for the functional nodes. | .gif) | CreateControlStyle | Creates the style object that is used internally by the WebControl class to implement all style related properties. This method is used primarily by control developers. (Inherited from WebControl.) | .gif) | DataBind()()() | Infrastructure. Binds a data source to the SiteMapPath control and its child controls. (Overrides CompositeControl..::.DataBind()()().) | .gif) | DataBind(Boolean) | Binds a data source to the invoked server control and all its child controls with an option to raise the DataBinding event. (Inherited from Control.) | .gif) | DataBindChildren | Binds a data source to the server control's child controls. (Inherited from Control.) | .gif) | Dispose | Enables a server control to perform final clean up before it is released from memory. (Inherited from Control.) | .gif) | EnsureChildControls | Determines whether the server control contains child controls. If it does not, it creates child controls. (Inherited from Control.) | .gif) | EnsureID | Creates an identifier for controls that do not have an identifier assigned. (Inherited from Control.) | .gif) | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | .gif) | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | .gif) | FindControl(String) | Searches the current naming container for a server control with the specified id parameter. (Inherited from Control.) | .gif) | FindControl(String, Int32) | Infrastructure. Searches the current naming container for a server control with the specified id and an integer, specified in the pathOffset parameter, which aids in the search. You should not override this version of the FindControl method. (Inherited from Control.) | .gif) | Focus | Sets input focus to a control. (Inherited from Control.) | .gif) | GetDesignModeState | Infrastructure. Gets design-time data for a control. (Inherited from Control.) | .gif) | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | .gif) | GetRouteUrl(Object) | Gets the URL that corresponds to a set of route parameters. (Inherited from Control.) | .gif) | GetRouteUrl(RouteValueDictionary) | Gets the URL that corresponds to a set of route parameters. (Inherited from Control.) | .gif) | GetRouteUrl(String, Object) | Gets the URL that corresponds to a set of route parameters and a route name. (Inherited from Control.) | .gif) | GetRouteUrl(String, RouteValueDictionary) | Gets the URL that corresponds to a set of route parameters and a route name. (Inherited from Control.) | .gif) | GetType | Gets the Type of the current instance. (Inherited from Object.) | .gif) | GetUniqueIDRelativeTo | Returns the prefixed portion of the UniqueID property of the specified control. (Inherited from Control.) | .gif) | HasControls | Determines if the server control contains any child controls. (Inherited from Control.) | .gif) | HasEvents | Returns a value indicating whether events are registered for the control or any child controls. (Inherited from Control.) | .gif) | InitializeItem | Populates a SiteMapNodeItem, which is a Web server control that represents a SiteMapNode, with a set of child controls based on the node's function and the specified templates and styles for the node. | .gif) | IsLiteralContent | Infrastructure. Determines if the server control holds only literal content. (Inherited from Control.) | .gif) | LoadControlState | Restores control-state information from a previous page request that was saved by the SaveControlState method. (Inherited from Control.) | .gif) | LoadViewState | Restores view-state information from a previous request that was saved with the SaveViewState method. (Overrides WebControl..::.LoadViewState(Object).) | .gif) | MapPathSecure | Retrieves the physical path that a virtual path, either absolute or relative, maps to. (Inherited from Control.) | .gif) | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | .gif) | MergeStyle | Copies any nonblank elements of the specified style to the Web control, but will not overwrite any existing style elements of the control. This method is used primarily by control developers. (Inherited from WebControl.) | .gif) | OnBubbleEvent | Determines whether the event for the server control is passed up the page's UI server control hierarchy. (Inherited from Control.) | .gif) | OnDataBinding | Infrastructure. Overrides the OnDataBinding method of the CompositeControl class and raises the DataBinding event. (Overrides Control..::.OnDataBinding(EventArgs).) | .gif) | OnInit | Raises the Init event. (Inherited from Control.) | .gif) | OnItemCreated | Raises the ItemCreated event of the SiteMapPath control. | .gif) | OnItemDataBound | Raises the ItemDataBound event of the SiteMapPath control. | .gif) | OnLoad | Raises the Load event. (Inherited from Control.) | .gif) | OnPreRender | Raises the PreRender event. (Inherited from Control.) | .gif) | OnUnload | Raises the Unload event. (Inherited from Control.) | .gif) | OpenFile | Gets a Stream used to read a file. (Inherited from Control.) | .gif) | RaiseBubbleEvent | Assigns any sources of the event and its information to the control's parent. (Inherited from Control.) | .gif) | RecreateChildControls | Recreates the child controls in a control derived from CompositeControl. (Inherited from CompositeControl.) | .gif) | RemovedControl | Called after a child control is removed from the Controls collection of the Control object. (Inherited from Control.) | .gif) | Render | Writes the CompositeControl content to the specified HtmlTextWriter object, for display on the client. (Overrides CompositeControl..::.Render(HtmlTextWriter).) | .gif) | RenderBeginTag | Renders the HTML opening tag of the control to the specified writer. This method is used primarily by control developers. (Inherited from WebControl.) | .gif) | RenderChildren | Outputs the content of a server control's children to a provided HtmlTextWriter object, which writes the content to be rendered on the client. (Inherited from Control.) | .gif) | RenderContents | Renders the nodes in the SiteMapPath control. (Overrides WebControl..::.RenderContents(HtmlTextWriter).) | .gif) | RenderControl(HtmlTextWriter) | Outputs server control content to a provided HtmlTextWriter object and stores tracing information about the control if tracing is enabled. (Inherited from Control.) | .gif) | RenderControl(HtmlTextWriter, ControlAdapter) | Outputs server control content to a provided HtmlTextWriter object using a provided ControlAdapter object. (Inherited from Control.) | .gif) | RenderEndTag | Renders the HTML closing tag of the control into the specified writer. This method is used primarily by control developers. (Inherited from WebControl.) | .gif) | ResolveAdapter | Gets the control adapter responsible for rendering the specified control. (Inherited from Control.) | .gif) | ResolveClientUrl | Gets a URL that can be used by the browser. (Inherited from Control.) | .gif) | ResolveUrl | Converts a URL into one that is usable on the requesting client. (Inherited from Control.) | .gif) | SaveControlState | Saves any server control state changes that have occurred since the time the page was posted back to the server. (Inherited from Control.) | .gif) | SaveViewState | Infrastructure. Saves changes to view state for the SiteMapPath control. (Overrides WebControl..::.SaveViewState()()().) | .gif) | SetDesignModeState | Sets design-time data for a control. (Inherited from Control.) | .gif) | SetRenderMethodDelegate | Infrastructure. Assigns an event handler delegate to render the server control and its content into its parent control. (Inherited from Control.) | .gif) | ToString | Returns a string that represents the current object. (Inherited from Object.) | .gif) | TrackViewState | Infrastructure. Tracks changes to the SiteMapPath control's view state. (Overrides WebControl..::.TrackViewState()()().) | Top

Extension Methods

Explicit Interface Implementations
|
| Name | Description |
|---|
.gif) .gif) | IAttributeAccessor..::.GetAttribute | Infrastructure. Gets an attribute of the Web control with the specified name. (Inherited from WebControl.) | .gif) .gif) | IAttributeAccessor..::.SetAttribute | Sets an attribute of the Web control to the specified name and value. (Inherited from WebControl.) | .gif) .gif) | ICompositeControlDesignerAccessor..::.RecreateChildControls | Enables a designer to recreate the composite control's collection of child controls in the design-time environment. (Inherited from CompositeControl.) | .gif) .gif) | IControlBuilderAccessor..::.ControlBuilder | For a description of this member, see IControlBuilderAccessor..::.ControlBuilder. (Inherited from Control.) | .gif) .gif) | IControlDesignerAccessor..::.GetDesignModeState | For a description of this member, see IControlDesignerAccessor..::.GetDesignModeState. (Inherited from Control.) | .gif) .gif) | IControlDesignerAccessor..::.SetDesignModeState | For a description of this member, see IControlDesignerAccessor..::.SetDesignModeState. (Inherited from Control.) | .gif) .gif) | IControlDesignerAccessor..::.SetOwnerControl | Infrastructure. For a description of this member, see IControlDesignerAccessor..::.SetOwnerControl. (Inherited from Control.) | .gif) .gif) | IControlDesignerAccessor..::.UserData | For a description of this member, see IControlDesignerAccessor..::.UserData. (Inherited from Control.) | .gif) .gif) | IDataBindingsAccessor..::.DataBindings | For a description of this member, see IDataBindingsAccessor..::.DataBindings. (Inherited from Control.) | .gif) .gif) | IDataBindingsAccessor..::.HasDataBindings | For a description of this member, see IDataBindingsAccessor..::.HasDataBindings. (Inherited from Control.) | .gif) .gif) | IExpressionsAccessor..::.Expressions | For a description of this member, see IExpressionsAccessor..::.Expressions. (Inherited from Control.) | .gif) .gif) | IExpressionsAccessor..::.HasExpressions | For a description of this member, see IExpressionsAccessor..::.HasExpressions. (Inherited from Control.) | .gif) .gif) | IParserAccessor..::.AddParsedSubObject | For a description of this member, see IParserAccessor..::.AddParsedSubObject. (Inherited from Control.) | Top

Remarks
In this topic: IntroductionThe SiteMapPath control is a site navigation control that reflects data provided by the SiteMap object. It provides a space-saving way to easily navigate a site and serves as a point of reference for where the currently displayed page is within a site. This type of control is commonly called a breadcrumb, or eyebrow, because it displays a hierarchical path of hyperlinked page names that provides an escape up the hierarchy of pages from the current location. SiteMapDataSource. The SiteMapPath is useful for sites that have deep hierarchical page structures, but where a TreeView or Menu might require too much space on a page. The SiteMapPath control works directly with your Web site's site map data. If you use it on a page that is not represented in your site map, it will not be displayed. For more information about site maps, see ASP.NET Site Navigation. NodesThe SiteMapPath is made up of nodes. Each element in the path is called a node and is represented by a SiteMapNodeItem object. The node that anchors the path and represents the base of the hierarchical tree is called the root node. The node that represents the currently displayed page is the current node. Any other node between the current node and root node is a parent node. The following table describes the three different node types. Node type | Description |
|---|
root | A node that anchors a hierarchical set of nodes. | parent | A node that has one or more child nodes, but is not the current node. | current | A node that represents the currently displayed page. |
Node AppearanceEach node displayed by a SiteMapPath is a HyperLink or Literal control that you can apply a template or style to. The templates and styles are applied to nodes according to two rules of precedence: If a template is defined for a node, it overrides any style defined for the node. Templates and styles that are specific to types of nodes override general templates and styles defined for all nodes.
The NodeStyle and NodeTemplate properties are applied to all nodes, regardless of their node type. If both these properties are defined, the NodeTemplate takes precedence. The CurrentNodeTemplate and CurrentNodeStyle properties are applied to nodes that represent the currently displayed page. If a NodeTemplate is defined in addition to the CurrentNodeTemplate, it is ignored. If a NodeStyle is defined in addition to the CurrentNodeStyle, it is merged with the CurrentNodeStyle to create a merged style. This merged style uses all the elements of the CurrentNodeStyle, plus any additional elements of the NodeStyle that do not conflict with the CurrentNodeStyle. The RootNodeTemplate and RootNodeStyle properties are applied to the node that represents the root of the site navigation hierarchy. If a NodeTemplate is defined in addition to the RootNodeTemplate, it is ignored. If a NodeStyle is defined in addition to the RootNodeStyle, it is merged with the RootNodeStyle to create a merged style. This merged style uses all the elements of the RootNodeStyle, plus any additional elements of the NodeStyle that did not conflict with the CurrentNodeStyle. Finally, if the currently displayed page is the root page of the site, the RootNodeTemplate and RootNodeStyle are used instead of the CurrentNodeTemplate or CurrentNodeStyle. The SiteMapPath control uses the site map provider identified by the SiteMapProvider property as its data source for site navigation information. If no provider is specified, it uses the default provider for the site, identified in the SiteMap..::.Provider property. Typically, this is an instance of the default site map provider for ASP.NET, the XmlSiteMapProvider. If the SiteMapPath control is used within a site but no site map provider is configured, the control throws an HttpException exception. EventsThe SiteMapPath control also provides events that you can program against. This allows you to run a custom routine whenever an event occurs. The following table lists the events supported by the SiteMapPath control. Customizing the SiteMapPath ControlAccessibilityDeclarative Syntax
<asp:SiteMapPath
AccessKey="string"
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
Inset|Outset"
BorderWidth="size"
CssClass="string"
Enabled="True|False"
EnableTheming="True|False"
EnableViewState="True|False"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
ID="string"
OnDataBinding="DataBinding event handler"
OnDisposed="Disposed event handler"
OnInit="Init event handler"
OnItemCreated="ItemCreated event handler"
OnItemDataBound="ItemDataBound event handler"
OnLoad="Load event handler"
OnPreRender="PreRender event handler"
OnUnload="Unload event handler"
ParentLevelsDisplayed="integer"
PathDirection="RootToCurrent|CurrentToRoot"
PathSeparator="string"
RenderCurrentNodeAsLink="True|False"
runat="server"
ShowToolTips="True|False"
SiteMapProvider="string"
SkinID="string"
SkipLinkText="string"
Style="string"
TabIndex="integer"
ToolTip="string"
Visible="True|False"
Width="size"
>
<CurrentNodeStyle />
<CurrentNodeTemplate>
<!-- child controls -->
</CurrentNodeTemplate>
<NodeStyle />
<NodeTemplate>
<!-- child controls -->
</NodeTemplate>
<PathSeparatorStyle />
<PathSeparatorTemplate>
<!-- child controls -->
</PathSeparatorTemplate>
<RootNodeStyle />
<RootNodeTemplate>
<!-- child controls -->
</RootNodeTemplate>
</asp:SiteMapPath>

Examples
The following code example uses a SiteMapPath control declaratively in a Web Forms page. This example demonstrates some of the rules of precedence that govern the order with which templates and styles are applied to SiteMapPath nodes.
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<!-- The following example demonstrates some of the orders
of precedence when applying styles and templates to
functional nodes of a SiteMapPath.
The NodeStyle and RootNodeStyle define the same attributes,
but are different and conflict with each other: the
RootNodeStyle supersedes NodeStyle, and is the style
rendered. Notice, however, that the underline style
defined by NodeStyle is still applied.
Both a CurrentNodeStyle and a CurrentNodeTemplate are
defined. A template supersedes a style for a node
type, so CurrentNodeTemplate is displayed and CurrentNodeStyle
is ignored. -->
<asp:SiteMapPath ID="SiteMapPath1" runat="server"
RenderCurrentNodeAsLink="true"
NodeStyle-Font-Names="Franklin Gothic Medium"
NodeStyle-Font-Underline="true"
NodeStyle-Font-Bold="true"
RootNodeStyle-Font-Names="Symbol"
RootNodeStyle-Font-Bold="false"
CurrentNodeStyle-Font-Names="Verdana"
CurrentNodeStyle-Font-Size="10pt"
CurrentNodeStyle-Font-Bold="true"
CurrentNodeStyle-ForeColor="red"
CurrentNodeStyle-Font-Underline="false">
<CURRENTNODETEMPLATE>
<asp:Image id="Image1" runat="server" ImageUrl="WebForm2.jpg" AlternateText="WebForm2"/>
</CURRENTNODETEMPLATE>
</asp:SiteMapPath>
</form>
</body>
</html>
<%@ 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">
</script>
<html >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<!-- The following example demonstrates some of the orders
of precedence when applying styles and templates to
functional nodes of a SiteMapPath.
The NodeStyle and RootNodeStyle define the same attributes,
but are different and conflict with each other: the
RootNodeStyle supersedes NodeStyle, and is the style
rendered. Notice, however, that the underline style
defined by NodeStyle is still applied.
Both a CurrentNodeStyle and a CurrentNodeTemplate are
defined. A template supersedes a style for a node
type, so CurrentNodeTemplate is displayed and CurrentNodeStyle
is ignored. -->
<asp:SiteMapPath ID="SiteMapPath1" runat="server"
RenderCurrentNodeAsLink="true"
NodeStyle-Font-Names="Franklin Gothic Medium"
NodeStyle-Font-Underline="true"
NodeStyle-Font-Bold="true"
RootNodeStyle-Font-Names="Symbol"
RootNodeStyle-Font-Bold="false"
CurrentNodeStyle-Font-Names="Verdana"
CurrentNodeStyle-Font-Size="10pt"
CurrentNodeStyle-Font-Bold="true"
CurrentNodeStyle-ForeColor="red"
CurrentNodeStyle-Font-Underline="false">
<CURRENTNODETEMPLATE>
<asp:Image id="Image1" runat="server" ImageUrl="WebForm2.jpg" AlternateText="WebForm2"/>
</CURRENTNODETEMPLATE>
</asp:SiteMapPath>
</form>
</body>
</html>
The previous example uses the default site map provider and a Web.sitemap file with the following structure.
<siteMap>
<siteMapNode title="WebForm1" description="WebForm1" url="WebForm1.aspx" >
<siteMapNode title="WebForm2" description="WebForm2" url="WebForm2.aspx"/>
</siteMapNode>
</siteMap>
The following code example demonstrates extends the SiteMapPath control and adds new functionality to it by overriding the InitializeItem method. The DropDownSiteMapPath control adds a DropDownList after the current node, to enable easy navigation to pages that are child nodes of the current page. This example demonstrates how to work with SiteMapNodeItem objects, including checking their SiteMapNodeItemType and calling the OnItemCreated method after the items are created.
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Security.Permissions
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Namespace Samples.AspNet
' The DropDownNavigationPath is a class that extends the SiteMapPath
' control and renders a DropDownList after the CurrentNode. The
' DropDownList displays a list of pages found further down the site map
' hierarchy from the current one. Selecting an item in the DropDownList
' redirects to that page.
'
' For simplicity, the DropDownNavigationPath assumes the
' RootToCurrent PathDirection, and does not apply styles
' or templates the current node.
'
<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class DropDownNavigationPath
Inherits SiteMapPath
' Override the InitializeItem method to add a PathSeparator
' and DropDownList to the current node.
Protected Overrides Sub InitializeItem(item As SiteMapNodeItem)
' The only node that must be handled is the CurrentNode.
If item.ItemType = SiteMapNodeItemType.Current Then
Dim hLink As New HyperLink()
' No Theming for the HyperLink.
hLink.EnableTheming = False
' Enable the link of the SiteMapPath is enabled.
hLink.Enabled = Me.Enabled
' Set the properties of the HyperLink to
' match those of the corresponding SiteMapNode.
hLink.NavigateUrl = item.SiteMapNode.Url
hLink.Text = item.SiteMapNode.Title
If ShowToolTips Then
hLink.ToolTip = item.SiteMapNode.Description
End If
' Apply styles or templates to the HyperLink here.
' ...
' ...
' Add the item to the Controls collection.
item.Controls.Add(hLink)
AddDropDownListAfterCurrentNode(item)
Else
MyBase.InitializeItem(item)
End If
End Sub 'InitializeItem
Private Sub AddDropDownListAfterCurrentNode(item As SiteMapNodeItem)
Dim childNodes As SiteMapNodeCollection = item.SiteMapNode.ChildNodes
' Only do this work if there are child nodes.
If Not (childNodes Is Nothing) Then
' Add another PathSeparator after the CurrentNode.
Dim finalSeparator As New SiteMapNodeItem(item.ItemIndex, SiteMapNodeItemType.PathSeparator)
Dim eventArgs As New SiteMapNodeItemEventArgs(finalSeparator)
InitializeItem(finalSeparator)
' Call OnItemCreated every time a SiteMapNodeItem is
' created and initialized.
OnItemCreated(eventArgs)
' The pathSeparator does not bind to any SiteMapNode, so
' do not call DataBind on the SiteMapNodeItem.
item.Controls.Add(finalSeparator)
' Create a DropDownList and populate it with the children of the
' CurrentNode. There are no styles or templates that are applied
' to the DropDownList control. If OnSelectedIndexChanged is raised,
' the event handler redirects to the page selected.
' The CurrentNode has child nodes.
Dim ddList As New DropDownList()
ddList.AutoPostBack = True
AddHandler ddList.SelectedIndexChanged, AddressOf Me.DropDownNavPathEventHandler
' Add a ListItem to the DropDownList for every node in the
' SiteMapNodes collection.
Dim node As SiteMapNode
For Each node In childNodes
ddList.Items.Add(New ListItem(node.Title, node.Url))
Next node
item.Controls.Add(ddList)
End If
End Sub 'AddDropDownListAfterCurrentNode
' The sender is the DropDownList.
Private Sub DropDownNavPathEventHandler(sender As Object, e As EventArgs)
Dim ddL As DropDownList = CType(sender, DropDownList)
' Redirect to the page the user chose.
If Not (Context Is Nothing) Then
Context.Response.Redirect(ddL.SelectedValue)
End If
End Sub 'DropDownNavPathEventHandler
End Class 'DropDownNavigationPath
End Namespace
using System;
using System.Collections;
using System.ComponentModel;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
// The DropDownNavigationPath is a class that extends the SiteMapPath
// control and renders a DropDownList after the CurrentNode. The
// DropDownList displays a list of pages found further down the site map
// hierarchy from the current one. Selecting an item in the DropDownList
// redirects to that page.
//
// For simplicity, the DropDownNavigationPath assumes the
// RootToCurrent PathDirection, and does not apply styles
// or templates the current node.
//
[AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
public class DropDownNavigationPath : SiteMapPath {
// Override the InitializeItem method to add a PathSeparator
// and DropDownList to the current node.
protected override void InitializeItem(SiteMapNodeItem item) {
// The only node that must be handled is the CurrentNode.
if (item.ItemType == SiteMapNodeItemType.Current)
{
HyperLink hLink = new HyperLink();
// No Theming for the HyperLink.
hLink.EnableTheming = false;
// Enable the link of the SiteMapPath is enabled.
hLink.Enabled = this.Enabled;
// Set the properties of the HyperLink to
// match those of the corresponding SiteMapNode.
hLink.NavigateUrl = item.SiteMapNode.Url;
hLink.Text = item.SiteMapNode.Title;
if (ShowToolTips) {
hLink.ToolTip = item.SiteMapNode.Description;
}
// Apply styles or templates to the HyperLink here.
// ...
// ...
// Add the item to the Controls collection.
item.Controls.Add(hLink);
AddDropDownListAfterCurrentNode(item);
}
else {
base.InitializeItem(item);
}
}
private void AddDropDownListAfterCurrentNode(SiteMapNodeItem item) {
SiteMapNodeCollection childNodes = item.SiteMapNode.ChildNodes;
// Only do this work if there are child nodes.
if (childNodes != null) {
// Add another PathSeparator after the CurrentNode.
SiteMapNodeItem finalSeparator =
new SiteMapNodeItem(item.ItemIndex,
SiteMapNodeItemType.PathSeparator);
SiteMapNodeItemEventArgs eventArgs =
new SiteMapNodeItemEventArgs(finalSeparator);
InitializeItem(finalSeparator);
// Call OnItemCreated every time a SiteMapNodeItem is
// created and initialized.
OnItemCreated(eventArgs);
// The pathSeparator does not bind to any SiteMapNode, so
// do not call DataBind on the SiteMapNodeItem.
item.Controls.Add(finalSeparator);
// Create a DropDownList and populate it with the children of the
// CurrentNode. There are no styles or templates that are applied
// to the DropDownList control. If OnSelectedIndexChanged is raised,
// the event handler redirects to the page selected.
// The CurrentNode has child nodes.
DropDownList ddList = new DropDownList();
ddList.AutoPostBack = true;
ddList.SelectedIndexChanged += new EventHandler(this.DropDownNavPathEventHandler);
// Add a ListItem to the DropDownList for every node in the
// SiteMapNodes collection.
foreach (SiteMapNode node in childNodes) {
ddList.Items.Add(new ListItem(node.Title, node.Url));
}
item.Controls.Add(ddList);
}
}
// The sender is the DropDownList.
private void DropDownNavPathEventHandler(object sender,EventArgs e) {
DropDownList ddL = sender as DropDownList;
// Redirect to the page the user chose.
if (Context != null)
Context.Response.Redirect(ddL.SelectedValue);
}
}

Version Information
.NET FrameworkSupported in: 4, 3.5, 3.0, 2.0

Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), 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.

Thread Safety
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also
|
Bibliothèque de classes .NET Framework SiteMapPath, classe Affiche un jeu de texte ou des images-liens hypertexte qui occupent un espace de page restreint et permettent aux utilisateurs de naviguer plus facilement sur un site Web.

Hiérarchie d'héritage
Espace de noms :
System.Web.UI.WebControls
Assembly :
System.Web (dans System.Web.dll)

Syntaxe
Public Class SiteMapPath _
Inherits CompositeControl
public class SiteMapPath : CompositeControl
public ref class SiteMapPath : public CompositeControl
type SiteMapPath =
class
inherit CompositeControl
end
Le type SiteMapPath expose les membres suivants.

Constructeurs
|
| Nom | Description |
|---|
.gif) | SiteMapPath | Initialise une nouvelle instance de la classe SiteMapPath. | Début

Méthodes
|
| Nom | Description |
|---|
.gif) | AddAttributesToRender | Ajoute des attributs et des styles HTML qui doivent être rendus au HtmlTextWriterTag spécifié. Cette méthode est principalement utilisée par des développeurs de contrôles. (Hérité de WebControl.) | .gif) | AddedControl | Appelée après l'ajout d'un contrôle enfant à la collection Controls de l'objet Control. (Hérité de Control.) | .gif) | AddParsedSubObject | Avertit le contrôle serveur qu'un élément XML ou HTML a été analysé et l'ajoute à l'objet ControlCollection du contrôle serveur. (Hérité de Control.) | .gif) | ApplyStyle | Copie tous les éléments non vides du style spécifié vers le contrôle Web, en remplaçant les éléments de style existants du contrôle. Cette méthode est principalement utilisée par des développeurs de contrôles. (Hérité de WebControl.) | .gif) | ApplyStyleSheetSkin | Applique les propriétés de style définies dans la feuille de style de la page au contrôle. (Hérité de Control.) | .gif) | BuildProfileTree | Infrastructure. Collecte des informations sur le contrôle serveur et les livre à la propriété Trace à afficher lorsque le traçage est activé pour la page. (Hérité de Control.) | .gif) | ClearCachedClientID | Infrastructure. Affecte à la valeur ClientID mise en cache la valeur nullNothingnullptrune référence null (Nothing en Visual Basic). (Hérité de Control.) | .gif) | ClearChildControlState | Supprime les informations sur l'état du contrôle des contrôles enfants du contrôle serveur. (Hérité de Control.) | .gif) | ClearChildState | Supprime les informations sur l'état d'affichage et sur l'état du contrôle de tous les contrôles enfants du contrôle serveur. (Hérité de Control.) | .gif) | ClearChildViewState | Supprime les informations d'état d'affichage de tous les contrôles enfants du contrôle serveur. (Hérité de Control.) | .gif) | ClearEffectiveClientIDMode | Infrastructure. Affecte la valeur Inherit à la propriété ClientIDMode de l'instance de contrôle actuelle et de tous contrôles enfants. (Hérité de Control.) | .gif) | CopyBaseAttributes | Copie les propriétés non encapsulées par l'objet Style du contrôle serveur Web spécifié vers le contrôle serveur Web à partir duquel cette méthode est appelée. Cette méthode est principalement utilisée par des développeurs de contrôles. (Hérité de WebControl.) | .gif) | CreateChildControls | Infrastructure. Efface la collection de contrôles enfants actuelle et la reconstruit en appelant la méthode CreateControlHierarchy. (Substitue Control..::.CreateChildControls()()().) | .gif) | CreateControlCollection | Crée un nouvel objet ControlCollection pour contenir les contrôles enfants (littéraux et serveur) du contrôle serveur. (Hérité de Control.) | .gif) | CreateControlHierarchy | Examine la structure du plan de site fournie par le SiteMapProvider et construit une collection de contrôles enfants basée sur les styles et les modèles définis pour les nœuds fonctionnels. | .gif) | CreateControlStyle | Crée l'objet de style qui est utilisé de manière interne par la classe WebControl pour implémenter toutes les propriétés associées au style. Cette méthode est principalement utilisée par des développeurs de contrôles. (Hérité de WebControl.) | .gif) | DataBind()()() | Infrastructure. Lie une source de données au contrôle SiteMapPath et à ses contrôles enfants. (Substitue CompositeControl..::.DataBind()()().) | .gif) | DataBind(Boolean) | Lie une source de données au contrôle serveur appelé et tous ses contrôles enfants avec une option pour déclencher l'événement DataBinding. (Hérité de Control.) | .gif) | DataBindChildren | Lie une source de données aux contrôles enfants du contrôle serveur. (Hérité de Control.) | .gif) | Dispose | Permet à un contrôle serveur d'effectuer le nettoyage final avant qu'il soit libéré de la mémoire. (Hérité de Control.) | .gif) | EnsureChildControls | Détermine si le contrôle serveur contient des contrôles enfants. S'il ne contient pas de contrôles enfants, il en crée. (Hérité de Control.) | .gif) | EnsureID | Crée un identificateur pour les contrôles auxquels aucun identificateur n'est assigné. (Hérité de Control.) | .gif) | Equals(Object) | Détermine si l'Object spécifié est égal à l'Object en cours. (Hérité de Object.) | .gif) | Finalize | Autorise un objet à tenter de libérer des ressources et d'exécuter d'autres opérations de netto***ge avant qu'il ne soit récupéré par l'opération garbage collection. (Hérité de Object.) | .gif) | FindControl(String) | Recherche un contrôle serveur possédant le paramètre id spécifié dans le conteneur d'attribution de noms actuel. (Hérité de Control.) | .gif) | FindControl(String, Int32) | Infrastructure. Recherche le conteneur d'attribution de noms actuel d'un contrôle serveur avec l'id spécifié et un entier, spécifié dans le paramètre pathOffset, qui facilite la recherche. Vous ne devez pas substituer cette version de la méthode FindControl. (Hérité de Control.) | .gif) | Focus | Affecte le focus d'entrée à un contrôle. (Hérité de Control.) | .gif) | GetDesignModeState | Infrastructure. Obtient les données au moment du design pour un contrôle. (Hérité de Control.) | .gif) | GetHashCode | Sert de fonction de hachage pour un type particulier. (Hérité de Object.) | .gif) | GetRouteUrl(Object) | Obtient l'URL qui correspond à un jeu de paramètres d'itinéraire. (Hérité de Control.) | .gif) | GetRouteUrl(RouteValueDictionary) | Obtient l'URL qui correspond à un jeu de paramètres d'itinéraire. (Hérité de Control.) | .gif) | GetRouteUrl(String, Object) | Obtient l'URL qui correspond à un jeu de paramètres d'itinéraire et à un nom d'itinéraire. (Hérité de Control.) | .gif) | GetRouteUrl(String, RouteValueDictionary) | Obtient l'URL qui correspond à un jeu de paramètres d'itinéraire et à un nom d'itinéraire. (Hérité de Control.) | .gif) | GetType | Obtient le Type de l'instance actuelle. (Hérité de Object.) | .gif) | GetUniqueIDRelativeTo | Retourne la partie préfixée de la propriété UniqueID du contrôle spécifié. (Hérité de Control.) | .gif) | HasControls | Détermine si le contrôle serveur contient des contrôles enfants. (Hérité de Control.) | .gif) | HasEvents | Retourne une valeur indiquant si des événements sont inscrits pour le contrôle ou des contrôles enfants. (Hérité de Control.) | .gif) | InitializeItem | Remplit un SiteMapNodeItem, qui est un contrôle serveur Web qui représente un SiteMapNode, avec un jeu de contrôles enfants selon la fonction du nœud ainsi que des modèles et des styles spécifiés pour celui-ci. | .gif) | IsLiteralContent | Infrastructure. Détermine si le contrôle serveur ne détient qu'un contenu littéral. (Hérité de Control.) | .gif) | LoadControlState | Restaure des informations sur l'état du contrôle à partir d'une demande de page antérieure enregistrée par la méthode SaveControlState. (Hérité de Control.) | .gif) | LoadViewState | Restaure les informations d'état d'affichage à partir d'une précédente requête enregistrées avec la méthode SaveViewState. (Substitue WebControl..::.LoadViewState(Object).) | .gif) | MapPathSecure | Récupère le chemin d'accès physique auquel un chemin d'accès virtuel, absolu ou relatif, correspond. (Hérité de Control.) | .gif) | MemberwiseClone | Crée une copie superficielle de l'objet Object actif. (Hérité de Object.) | .gif) | MergeStyle | Copie tous les éléments non vides du style spécifié vers le contrôle Web, mais ne remplace aucun élément de style existant du contrôle. Cette méthode est principalement utilisée par des développeurs de contrôles. (Hérité de WebControl.) | .gif) | OnBubbleEvent | Détermine si l'événement pour le contrôle serveur est passé dans la hiérarchie des contrôles serveur de l'interface utilisateur de la page. (Hérité de Control.) | .gif) | OnDataBinding | Infrastructure. Substitue la méthode OnDataBinding de la classe CompositeControl et déclenche l'événement DataBinding. (Substitue Control..::.OnDataBinding(EventArgs).) | .gif) | OnInit | Déclenche l'événement Init. (Hérité de Control.) | .gif) | OnItemCreated | Déclenche l'événement ItemCreated du contrôle SiteMapPath. | .gif) | OnItemDataBound | Déclenche l'événement ItemDataBound du contrôle SiteMapPath. | .gif) | OnLoad | Déclenche l'événement Load. (Hérité de Control.) | .gif) | OnPreRender | Déclenche l'événement PreRender. (Hérité de Control.) | .gif) | OnUnload | Déclenche l'événement Unload. (Hérité de Control.) | .gif) | OpenFile | Obtient un Stream utilisé pour lire un fichier. (Hérité de Control.) | .gif) | RaiseBubbleEvent | Assigne les sources éventuelles de l'événement et ses informations au parent du contrôle. (Hérité de Control.) | .gif) | RecreateChildControls | Recrée les contrôles enfants dans un contrôle dérivé de CompositeControl. (Hérité de CompositeControl.) | .gif) | RemovedControl | Appelée après la suppression d'un contrôle enfant dans la collection Controls de l'objet Control. (Hérité de Control.) | .gif) | Render | Écrit le contenu CompositeControl dans l'objet HtmlTextWriter spécifié pour qu'il s'affiche sur le client. (Substitue CompositeControl..::.Render(HtmlTextWriter).) | .gif) | RenderBeginTag | Génère le rendu de la balise d'ouverture HTML du contrôle via le writer spécifié. Cette méthode est principalement utilisée par des développeurs de contrôles. (Hérité de WebControl.) | .gif) | RenderChildren | Renvoie le contenu des enfants d'un contrôle serveur dans un objet HtmlTextWriter fourni, qui écrit le contenu à rendre sur le client. (Hérité de Control.) | .gif) | RenderContents | Génère le rendu des nœuds dans le contrôle SiteMapPath. (Substitue WebControl..::.RenderContents(HtmlTextWriter).) | .gif) | RenderControl(HtmlTextWriter) | Renvoie le contenu du contrôle serveur dans un objet HtmlTextWriter fourni et stocke des informations de traçage au sujet du contrôle si le traçage est activé. (Hérité de Control.) | .gif) | RenderControl(HtmlTextWriter, ControlAdapter) | Génère le contenu du contrôle serveur dans un objet HtmlTextWriter à l'aide d'un objet ControlAdapter fourni. (Hérité de Control.) | .gif) | RenderEndTag | Génère le rendu de la balise de fermeture HTML du contrôle via le writer spécifié. Cette méthode est principalement utilisée par des développeurs de contrôles. (Hérité de WebControl.) | .gif) | ResolveAdapter | Obtient l'adaptateur de contrôles responsable du rendu du contrôle spécifié. (Hérité de Control.) | .gif) | ResolveClientUrl | Obtient une URL qui peut être utilisée par le navigateur. (Hérité de Control.) | .gif) | ResolveUrl | Convertit une URL en une URL que le client soit en mesure d'utiliser. (Hérité de Control.) | .gif) | SaveControlState | Enregistre les modifications éventuellement apportées à l'état du contrôle serveur depuis la publication de la page sur le serveur. (Hérité de Control.) | .gif) | SaveViewState | Infrastructure. Enregistre les modifications relatives à l'état d'affichage du contrôle SiteMapPath. (Substitue WebControl..::.SaveViewState()()().) | .gif) | SetDesignModeState | Définit les données au moment du design pour un contrôle. (Hérité de Control.) | .gif) | SetRenderMethodDelegate | Infrastructure. Assigne un délégué de gestionnaires d'événements pour générer le rendu du contrôle serveur et de son contenu dans son contrôle parent. (Hérité de Control.) | .gif) | ToString | Retourne une chaîne qui représente l'objet actuel. (Hérité de Object.) | .gif) | TrackViewState | Infrastructure. Suit les modifications apportées à l'état d'affichage du contrôle SiteMapPath. (Substitue WebControl..::.TrackViewState()()().) | Début

Méthodes d'extension

Implémentations d'interface explicite
|
| Nom | Description |
|---|
.gif) .gif) | IAttributeAccessor..::.GetAttribute | Infrastructure. Obtient un attribut du contrôle Web avec le nom spécifié. (Hérité de WebControl.) | .gif) .gif) | IAttributeAccessor..::.SetAttribute | Affecte au nom et à la valeur spécifiés un attribut du contrôle Web. (Hérité de WebControl.) | .gif) .gif) | ICompositeControlDesignerAccessor..::.RecreateChildControls | Permet à un concepteur de recréer dans l'environnement au moment du design la collection du contrôle composite de contrôles enfants. (Hérité de CompositeControl.) | .gif) .gif) | IControlBuilderAccessor..::.ControlBuilder | Pour obtenir une description de ce membre, consultez IControlBuilderAccessor..::.ControlBuilder. (Hérité de Control.) | .gif) .gif) | IControlDesignerAccessor..::.GetDesignModeState | Pour obtenir une description de ce membre, consultez IControlDesignerAccessor..::.GetDesignModeState. (Hérité de Control.) | .gif) .gif) | IControlDesignerAccessor..::.SetDesignModeState | Pour obtenir une description de ce membre, consultez IControlDesignerAccessor..::.SetDesignModeState. (Hérité de Control.) | .gif) .gif) | IControlDesignerAccessor..::.SetOwnerControl | Infrastructure. Pour obtenir une description de ce membre, consultez IControlDesignerAccessor..::.SetOwnerControl. (Hérité de Control.) | .gif) .gif) | IControlDesignerAccessor..::.UserData | Pour obtenir une description de ce membre, consultez IControlDesignerAccessor..::.UserData. (Hérité de Control.) | .gif) .gif) | IDataBindingsAccessor..::.DataBindings | Pour obtenir une description de ce membre, consultez IDataBindingsAccessor..::.DataBindings. (Hérité de Control.) | .gif) .gif) | IDataBindingsAccessor..::.HasDataBindings | Pour obtenir une description de ce membre, consultez IDataBindingsAccessor..::.HasDataBindings. (Hérité de Control.) | .gif) .gif) | IExpressionsAccessor..::.Expressions | Pour obtenir une description de ce membre, consultez IExpressionsAccessor..::.Expressions. (Hérité de Control.) | .gif) .gif) | IExpressionsAccessor..::.HasExpressions | Pour obtenir une description de ce membre, consultez IExpressionsAccessor..::.HasExpressions. (Hérité de Control.) | .gif) .gif) | IParserAccessor..::.AddParsedSubObject | Pour obtenir une description de ce membre, consultez IParserAccessor..::.AddParsedSubObject. (Hérité de Control.) | Début

Notes
Dans cette rubrique : IntroductionLe contrôle SiteMapPath est un contrôle de navigation de site qui reflète les données fournies par l'objet SiteMap. Il s'agit d'un outil de navigation compact également utilisé comme de point de référence pour déterminer l'emplacement de la page affichée sur un site. Ce type de contrôle est généralement appelé fil d'Ariane (breadcrumb) ou « sourcil » (eyebrow) parce qu'il affiche un chemin d'accès hiérarchique des noms de pages reliés par des liens hypertexte qui permettent de remonter la hiérarchie de pages à partir de l'emplacement actuel. SiteMapDataSource. SiteMapPath est utile pour les sites qui possèdent des structures de pages hiérarchiques profondes, mais où un TreeView ou un Menu peut requérir un espace important sur une page. Le contrôle SiteMapPath fonctionne directement avec les données de plan de site de votre site Web. Si vous l'utilisez sur une page qui n'est pas représentée dans votre plan de site, il ne sera pas affiché. Pour plus d'informations sur les plans de sites, consultez Navigation au sein des sites ASP.NET. NœudsLe SiteMapPath est composé de nœuds. Chaque élément du chemin d'accès est appelé un nœud et est représenté par un objet SiteMapNodeItem. Le nœud qui ancre le chemin d'accès et représente la base de l'arborescence hiérarchique est appelé le nœud racine. Le nœud qui représente la page affichée est le nœud actuel. Tout autre nœud situé entre le nœud actuel et le nœud racine est un nœud parent. Le tableau suivant décrit les trois types de nœuds. Type de nœud | Description |
|---|
racine | Nœud d'ancrage d'un jeu hiérarchique de nœuds. | parent | Nœud qui possède un ou plusieurs nœuds enfants, mais qui n'est pas le nœud actuel. | actuel | Nœud qui représente la page affichée. |
Apparence des nœudsChaque nœud affiché par un SiteMapPath est un contrôle HyperLink ou Literal auquel vous pouvez appliquer un modèle ou un style. Les modèles et les styles sont appliqués aux nœuds suivant deux règles de priorité : Si un modèle est défini pour un nœud, il substitue tout style défini pour celui-ci. Les modèles et les styles spécifiques aux types de nœuds se substituent aux modèles et styles généraux définis pour tous les nœuds.
Les propriétés NodeStyle et NodeTemplate sont appliquées à tous les nœuds, indépendamment de leur type. Si ces deux propriétés sont définies, la propriété NodeTemplate est prioritaire. Les propriétés CurrentNodeTemplate et CurrentNodeStyle sont appliquées aux nœuds qui représentent la page affichée. Si un NodeTemplate est défini en plus de CurrentNodeTemplate, il est ignoré. Si un NodeStyle est défini en plus de CurrentNodeStyle, il est fusionné avec le CurrentNodeStyle pour créer un style fusionné. Celui-ci utilise tous les éléments du CurrentNodeStyle ainsi que tous les éléments supplémentaires du NodeStyle qui ne sont pas en conflit avec le CurrentNodeStyle. Les propriétés RootNodeTemplate et RootNodeStyle sont appliquées au nœud qui représente la racine de la hiérarchie de navigation du site. Si un NodeTemplate est défini en plus de RootNodeTemplate, il est ignoré. Si un NodeStyle est défini en plus de RootNodeStyle, il est fusionné avec le RootNodeStyle pour créer un style fusionné. Celui-ci utilise tous les éléments du RootNodeStyle ainsi que tous les éléments supplémentaires du NodeStyle qui ne sont pas entrés en conflit avec le CurrentNodeStyle. Enfin, si la page affichée est la page racine du site, le RootNodeTemplate et le RootNodeStyle sont utilisés à la place du CurrentNodeTemplate ou du CurrentNodeStyle. Le contrôle SiteMapPath utilise le fournisseur de plan de site identifié par la propriété SiteMapProvider comme sa source de données pour obtenir des informations de navigation de site. Si aucun fournisseur n'est spécifié, il utilise le fournisseur par défaut pour le site, identifié dans la propriété SiteMap..::.Provider. Il s'agit généralement d'une instance du fournisseur de plan de site par défaut pour ASP.NET, le XmlSiteMapProvider. Si le contrôle SiteMapPath est utilisé dans un site mais qu'aucun fournisseur de plan de site n'est configuré, il lève une exception HttpException. ÉvénementsLe contrôle SiteMapPath fournit également des événements que vous pouvez programmer. Cela vous permet d'exécuter une routine personnalisée lorsqu'un événement se produit. Le tableau suivant répertorie les événements pris en charge par le contrôle SiteMapPath. Personnalisation du contrôle SiteMapPathAccessibilitéSyntaxe déclarative
<asp:SiteMapPath
AccessKey="string"
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
Inset|Outset"
BorderWidth="size"
CssClass="string"
Enabled="True|False"
EnableTheming="True|False"
EnableViewState="True|False"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
ID="string"
OnDataBinding="DataBinding event handler"
OnDisposed="Disposed event handler"
OnInit="Init event handler"
OnItemCreated="ItemCreated event handler"
OnItemDataBound="ItemDataBound event handler"
OnLoad="Load event handler"
OnPreRender="PreRender event handler"
OnUnload="Unload event handler"
ParentLevelsDisplayed="integer"
PathDirection="RootToCurrent|CurrentToRoot"
PathSeparator="string"
RenderCurrentNodeAsLink="True|False"
runat="server"
ShowToolTips="True|False"
SiteMapProvider="string"
SkinID="string"
SkipLinkText="string"
Style="string"
TabIndex="integer"
ToolTip="string"
Visible="True|False"
Width="size"
>
<CurrentNodeStyle />
<CurrentNodeTemplate>
<!-- child controls -->
</CurrentNodeTemplate>
<NodeStyle />
<NodeTemplate>
<!-- child controls -->
</NodeTemplate>
<PathSeparatorStyle />
<PathSeparatorTemplate>
<!-- child controls -->
</PathSeparatorTemplate>
<RootNodeStyle />
<RootNodeTemplate>
<!-- child controls -->
</RootNodeTemplate>
</asp:SiteMapPath>

Exemples
L'exemple de code suivant utilise un contrôle SiteMapPath de façon déclarative dans une page Web Forms. Cet exemple présente quelques règles de priorité régissant l'ordre d'application des modèles et des styles aux nœuds SiteMapPath.
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<!-- The following example demonstrates some of the orders
of precedence when applying styles and templates to
functional nodes of a SiteMapPath.
The NodeStyle and RootNodeStyle define the same attributes,
but are different and conflict with each other: the
RootNodeStyle supersedes NodeStyle, and is the style
rendered. Notice, however, that the underline style
defined by NodeStyle is still applied.
Both a CurrentNodeStyle and a CurrentNodeTemplate are
defined. A template supersedes a style for a node
type, so CurrentNodeTemplate is displayed and CurrentNodeStyle
is ignored. -->
<asp:SiteMapPath ID="SiteMapPath1" runat="server"
RenderCurrentNodeAsLink="true"
NodeStyle-Font-Names="Franklin Gothic Medium"
NodeStyle-Font-Underline="true"
NodeStyle-Font-Bold="true"
RootNodeStyle-Font-Names="Symbol"
RootNodeStyle-Font-Bold="false"
CurrentNodeStyle-Font-Names="Verdana"
CurrentNodeStyle-Font-Size="10pt"
CurrentNodeStyle-Font-Bold="true"
CurrentNodeStyle-ForeColor="red"
CurrentNodeStyle-Font-Underline="false">
<CURRENTNODETEMPLATE>
<asp:Image id="Image1" runat="server" ImageUrl="WebForm2.jpg" AlternateText="WebForm2"/>
</CURRENTNODETEMPLATE>
</asp:SiteMapPath>
</form>
</body>
</html>
<%@ 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">
</script>
<html >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<!-- The following example demonstrates some of the orders
of precedence when applying styles and templates to
functional nodes of a SiteMapPath.
The NodeStyle and RootNodeStyle define the same attributes,
but are different and conflict with each other: the
RootNodeStyle supersedes NodeStyle, and is the style
rendered. Notice, however, that the underline style
defined by NodeStyle is still applied.
Both a CurrentNodeStyle and a CurrentNodeTemplate are
defined. A template supersedes a style for a node
type, so CurrentNodeTemplate is displayed and CurrentNodeStyle
is ignored. -->
<asp:SiteMapPath ID="SiteMapPath1" runat="server"
RenderCurrentNodeAsLink="true"
NodeStyle-Font-Names="Franklin Gothic Medium"
NodeStyle-Font-Underline="true"
NodeStyle-Font-Bold="true"
RootNodeStyle-Font-Names="Symbol"
RootNodeStyle-Font-Bold="false"
CurrentNodeStyle-Font-Names="Verdana"
CurrentNodeStyle-Font-Size="10pt"
CurrentNodeStyle-Font-Bold="true"
CurrentNodeStyle-ForeColor="red"
CurrentNodeStyle-Font-Underline="false">
<CURRENTNODETEMPLATE>
<asp:Image id="Image1" runat="server" ImageUrl="WebForm2.jpg" AlternateText="WebForm2"/>
</CURRENTNODETEMPLATE>
</asp:SiteMapPath>
</form>
</body>
</html>
L'exemple précédent utilise le fournisseur de plan de site par défaut et un fichier Web.sitemap avec la structure suivante.
<siteMap>
<siteMapNode title="WebForm1" description="WebForm1" url="WebForm1.aspx" >
<siteMapNode title="WebForm2" description="WebForm2" url="WebForm2.aspx"/>
</siteMapNode>
</siteMap>
L'exemple de code suivant montre l'extension et l'ajout de nouvelles fonctionnalités au contrôle SiteMapPath en substituant la méthode InitializeItem. Le contrôle DropDownSiteMapPath ajoute un DropDownList après le nœud actuel afin de faciliter la navigation dans les pages qui sont des nœuds enfants de la page actuelle. Cet exemple montre comment utiliser les objets SiteMapNodeItem, y compris la vérification de leurs SiteMapNodeItemType et l'appel de la méthode OnItemCreated après que les éléments soient créés.
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Security.Permissions
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Namespace Samples.AspNet
' The DropDownNavigationPath is a class that extends the SiteMapPath
' control and renders a DropDownList after the CurrentNode. The
' DropDownList displays a list of pages found further down the site map
' hierarchy from the current one. Selecting an item in the DropDownList
' redirects to that page.
'
' For simplicity, the DropDownNavigationPath assumes the
' RootToCurrent PathDirection, and does not apply styles
' or templates the current node.
'
<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class DropDownNavigationPath
Inherits SiteMapPath
' Override the InitializeItem method to add a PathSeparator
' and DropDownList to the current node.
Protected Overrides Sub InitializeItem(item As SiteMapNodeItem)
' The only node that must be handled is the CurrentNode.
If item.ItemType = SiteMapNodeItemType.Current Then
Dim hLink As New HyperLink()
' No Theming for the HyperLink.
hLink.EnableTheming = False
' Enable the link of the SiteMapPath is enabled.
hLink.Enabled = Me.Enabled
' Set the properties of the HyperLink to
' match those of the corresponding SiteMapNode.
hLink.NavigateUrl = item.SiteMapNode.Url
hLink.Text = item.SiteMapNode.Title
If ShowToolTips Then
hLink.ToolTip = item.SiteMapNode.Description
End If
' Apply styles or templates to the HyperLink here.
' ...
' ...
' Add the item to the Controls collection.
item.Controls.Add(hLink)
AddDropDownListAfterCurrentNode(item)
Else
MyBase.InitializeItem(item)
End If
End Sub 'InitializeItem
Private Sub AddDropDownListAfterCurrentNode(item As SiteMapNodeItem)
Dim childNodes As SiteMapNodeCollection = item.SiteMapNode.ChildNodes
' Only do this work if there are child nodes.
If Not (childNodes Is Nothing) Then
' Add another PathSeparator after the CurrentNode.
Dim finalSeparator As New SiteMapNodeItem(item.ItemIndex, SiteMapNodeItemType.PathSeparator)
Dim eventArgs As New SiteMapNodeItemEventArgs(finalSeparator)
InitializeItem(finalSeparator)
' Call OnItemCreated every time a SiteMapNodeItem is
' created and initialized.
OnItemCreated(eventArgs)
' The pathSeparator does not bind to any SiteMapNode, so
' do not call DataBind on the SiteMapNodeItem.
item.Controls.Add(finalSeparator)
' Create a DropDownList and populate it with the children of the
' CurrentNode. There are no styles or templates that are applied
' to the DropDownList control. If OnSelectedIndexChanged is raised,
' the event handler redirects to the page selected.
' The CurrentNode has child nodes.
Dim ddList As New DropDownList()
ddList.AutoPostBack = True
AddHandler ddList.SelectedIndexChanged, AddressOf Me.DropDownNavPathEventHandler
' Add a ListItem to the DropDownList for every node in the
' SiteMapNodes collection.
Dim node As SiteMapNode
For Each node In childNodes
ddList.Items.Add(New ListItem(node.Title, node.Url))
Next node
item.Controls.Add(ddList)
End If
End Sub 'AddDropDownListAfterCurrentNode
' The sender is the DropDownList.
Private Sub DropDownNavPathEventHandler(sender As Object, e As EventArgs)
Dim ddL As DropDownList = CType(sender, DropDownList)
' Redirect to the page the user chose.
If Not (Context Is Nothing) Then
Context.Response.Redirect(ddL.SelectedValue)
End If
End Sub 'DropDownNavPathEventHandler
End Class 'DropDownNavigationPath
End Namespace
using System;
using System.Collections;
using System.ComponentModel;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
// The DropDownNavigationPath is a class that extends the SiteMapPath
// control and renders a DropDownList after the CurrentNode. The
// DropDownList displays a list of pages found further down the site map
// hierarchy from the current one. Selecting an item in the DropDownList
// redirects to that page.
//
// For simplicity, the DropDownNavigationPath assumes the
// RootToCurrent PathDirection, and does not apply styles
// or templates the current node.
//
[AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
public class DropDownNavigationPath : SiteMapPath {
// Override the InitializeItem method to add a PathSeparator
// and DropDownList to the current node.
protected override void InitializeItem(SiteMapNodeItem item) {
// The only node that must be handled is the CurrentNode.
if (item.ItemType == SiteMapNodeItemType.Current)
{
HyperLink hLink = new HyperLink();
// No Theming for the HyperLink.
hLink.EnableTheming = false;
// Enable the link of the SiteMapPath is enabled.
hLink.Enabled = this.Enabled;
// Set the properties of the HyperLink to
// match those of the corresponding SiteMapNode.
hLink.NavigateUrl = item.SiteMapNode.Url;
hLink.Text = item.SiteMapNode.Title;
if (ShowToolTips) {
hLink.ToolTip = item.SiteMapNode.Description;
}
// Apply styles or templates to the HyperLink here.
// ...
// ...
// Add the item to the Controls collection.
item.Controls.Add(hLink);
AddDropDownListAfterCurrentNode(item);
}
else {
base.InitializeItem(item);
}
}
private void AddDropDownListAfterCurrentNode(SiteMapNodeItem item) {
SiteMapNodeCollection childNodes = item.SiteMapNode.ChildNodes;
// Only do this work if there are child nodes.
if (childNodes != null) {
// Add another PathSeparator after the CurrentNode.
SiteMapNodeItem finalSeparator =
new SiteMapNodeItem(item.ItemIndex,
SiteMapNodeItemType.PathSeparator);
SiteMapNodeItemEventArgs eventArgs =
new SiteMapNodeItemEventArgs(finalSeparator);
InitializeItem(finalSeparator);
// Call OnItemCreated every time a SiteMapNodeItem is
// created and initialized.
OnItemCreated(eventArgs);
// The pathSeparator does not bind to any SiteMapNode, so
// do not call DataBind on the SiteMapNodeItem.
item.Controls.Add(finalSeparator);
// Create a DropDownList and populate it with the children of the
// CurrentNode. There are no styles or templates that are applied
// to the DropDownList control. If OnSelectedIndexChanged is raised,
// the event handler redirects to the page selected.
// The CurrentNode has child nodes.
DropDownList ddList = new DropDownList();
ddList.AutoPostBack = true;
ddList.SelectedIndexChanged += new EventHandler(this.DropDownNavPathEventHandler);
// Add a ListItem to the DropDownList for every node in the
// SiteMapNodes collection.
foreach (SiteMapNode node in childNodes) {
ddList.Items.Add(new ListItem(node.Title, node.Url));
}
item.Controls.Add(ddList);
}
}
// The sender is the DropDownList.
private void DropDownNavPathEventHandler(object sender,EventArgs e) {
DropDownList ddL = sender as DropDownList;
// Redirect to the page the user chose.
if (Context != null)
Context.Response.Redirect(ddL.SelectedValue);
}
}

Informations de version
.NET FrameworkPris en charge dans : 4, 3.5, 3.0, 2.0

Plateformes
Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows XP SP2 Édition x64, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

Sécurité des threads
Tous les membres static ( Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Voir aussi
RéférenceAutres ressources
|