SiteMapPath クラス
アセンブリ: System.Web (system.web.dll 内)

Public Class SiteMapPath Inherits CompositeControl
public class SiteMapPath : CompositeControl
public class SiteMapPath extends CompositeControl
public class SiteMapPath extends CompositeControl

SiteMapPath コントロールは、SiteMap オブジェクトに提供されるデータを反映するサイト ナビゲーション コントロールです。このコントロールは、サイト内を簡単に移動するコンパクトな手段を提供し、現在表示されているページのサイト内の位置を示す基準点の役割を果たします。この種のコントロールは一般に階層リンクなどと呼ばれます。ハイパーリンクのページ名で階層パスが表示され、これらを使用して現在の位置から階層の上位のページに直接移動できます。SiteMapDataSource。SiteMapPath は、階層構造が深く、TreeView や Menu を使用するとページ上に必要な領域が大きすぎるというサイトに有効です。
SiteMapPath コントロールは、Web サイトのサイト マップ データと直接連携します。サイト マップに表されないページ上で使用した場合、このコントロールは表示されません。サイト マップの詳細については、「ASP.NET サイト ナビゲーションの概要」を参照してください。
SiteMapPath はノードで構成されます。パス内の各要素はノードと呼ばれ、SiteMapNodeItem オブジェクトで表されます。パスの終端位置を定め、階層ツリーの基点を表すノードは、ルート ノードと呼ばれます。現在表示されているページを表すノードは、現在のノードと呼ばれます。現在のノードとルート ノードとの間にあるノードは親ノードです。3 つの異なるノード型の説明を以下に示します。
ノード型 | |
---|---|
SiteMapPath によって表示される各ノードは、テンプレートやスタイルを適用できる HyperLink コントロールまたは Literal コントロールです。テンプレートとスタイルは、次の 2 つの優先順位規則に従ってノードに適用されます。
NodeStyle プロパティと NodeTemplate プロパティは、ノード型に関係なくすべてのノードに適用されます。これらのプロパティが両方定義されている場合は、NodeTemplate が優先されます。
CurrentNodeTemplate プロパティと CurrentNodeStyle プロパティは、現在表示されているページを表すノードに適用されます。CurrentNodeTemplate に加えて NodeTemplate が定義された場合、無視されます。NodeStyle が CurrentNodeStyle に加えて定義された場合、CurrentNodeStyle とマージされ、マージされたスタイルが作成されます。このマージされたスタイルでは、CurrentNodeStyle のすべての要素に加え、CurrentNodeStyle と競合しない NodeStyle の追加要素が使用されます。
RootNodeTemplate プロパティと RootNodeStyle プロパティは、サイト ナビゲーション階層のルートを表すノードに適用されます。RootNodeTemplate に加えて NodeTemplate が定義された場合、無視されます。NodeStyle が RootNodeStyle に加えて定義された場合、RootNodeStyle とマージされ、マージされたスタイルが作成されます。このマージされたスタイルでは、RootNodeStyle のすべての要素に加え、CurrentNodeStyle と競合しない NodeStyle の追加要素が使用されます。最後に、現在表示されているページがサイトのルート ページの場合、CurrentNodeTemplate や CurrentNodeStyle の代わりに RootNodeTemplate と RootNodeStyle が使用されます。
SiteMapPath コントロールは、サイト ナビゲーション情報のデータ ソースとして、SiteMapProvider プロパティで識別されるサイト マップ プロバイダを使用します。プロバイダが指定されない場合、SiteMap.Provider プロパティで識別される、そのサイトの既定のプロバイダを使用します。一般に、これは ASP.NET の既定のサイト マップ プロバイダである XmlSiteMapProvider のインスタンスになります。サイト内で SiteMapPath コントロールが使用されているが、サイト マップ プロバイダが構成されていない場合、コントロールは HttpException 例外をスローします。
SiteMapPath コントロールには、プログラムから利用できるイベントも用意されています。これにより、イベントが発生するたびにカスタム ルーチンが実行されるようにできます。SiteMapPath コントロールでサポートされるイベントの一覧を次の表に示します。
ItemCreated | SiteMapPath コントロールが最初に SiteMapNodeItem を作成し、SiteMapNode に関連付けたときに発生します。 |
ItemDataBound | SiteMapNodeItem が SiteMapNode に格納されているサイト マップ データにバインドされたときに発生します。 |
SiteMapPath から派生したクラスは、InitializeItem メソッドをオーバーライドして、ナビゲーション コントロールに格納されている SiteMapNodeItem コントロールをカスタマイズします。完全に制御するために SiteMapNodeItem オブジェクトを作成し、CreateControlHierarchy メソッドをオーバーライドする SiteMapPath 派生クラスに追加します。
ユーザー補助
このコントロールに既定でレンダリングされるマークアップは、Web Content Accessibility Guidelines (WCAG) 1.0 の優先度 1 ガイドラインなどのユーザー補助に関する標準に適合しない可能性があります。このコントロールのユーザー補助サポートの詳細については、「ASP.NET コントロールとユーザー補助」を参照してください。

Web フォーム ページで宣言によって SiteMapPath コントロールを使用するコード例を次に示します。この例では、テンプレートとスタイルが 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> <BODY> <FORM 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-Name="Franklin Gothic Medium" NodeStyle-Font-Underline="true" NodeStyle-Font-Bold="true" RootNodeStyle-Font-Name="Symbol" RootNodeStyle-Font-Bold="false" CurrentNodeStyle-Font-Name="Verdana" CurrentNodeStyle-Font-Size="10pt" CurrentNodeStyle-Font-Bold="true" CurrentNodeStyle-ForeColor="red" CurrentNodeStyle-Font-Underline="false" HoverNodeStyle-ForeColor="blue" HoverNodeStyle-Font-Underline="true"> <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> <BODY> <FORM 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-Name="Franklin Gothic Medium" NodeStyle-Font-Underline="true" NodeStyle-Font-Bold="true" RootNodeStyle-Font-Name="Symbol" RootNodeStyle-Font-Bold="false" CurrentNodeStyle-Font-Name="Verdana" CurrentNodeStyle-Font-Size="10pt" CurrentNodeStyle-Font-Bold="true" CurrentNodeStyle-ForeColor="red" CurrentNodeStyle-Font-Underline="false" HoverNodeStyle-ForeColor="blue" HoverNodeStyle-Font-Underline="true"> <CURRENTNODETEMPLATE> <asp:Image id="Image1" runat="server" ImageUrl="WebForm2.jpg" AlternateText="WebForm2"/> </CURRENTNODETEMPLATE> </asp:SiteMapPath> </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"> </SCRIPT> <HTML> <BODY> <FORM 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 supercedes 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 supercedes a style for a node type, so CurrentNodeTemplate is displayed and CurrentNodeStyle is ignored. --> <asp:SiteMapPath ID="SiteMapPath1" runat="server" RenderCurrentNodeAsLink="true" NodeStyle-Font-Name="Franklin Gothic Medium" NodeStyle-Font-Underline="true" NodeStyle-Font-Bold="true" RootNodeStyle-Font-Name="Symbol" RootNodeStyle-Font-Bold="false" CurrentNodeStyle-Font-Name="Verdana" CurrentNodeStyle-Font-Size="10pt" CurrentNodeStyle-Font-Bold="true" CurrentNodeStyle-ForeColor="red" CurrentNodeStyle-Font-Underline="false" HoverNodeStyle-ForeColor="blue" HoverNodeStyle-Font-Underline="true"> <CURRENTNODETEMPLATE> <asp:Image id="Image1" runat="server" ImageUrl="WebForm2.jpg" AlternateText="WebForm2"/> </CURRENTNODETEMPLATE> </asp:SiteMapPath> </FORM> </BODY> </HTML>
上記の例では、既定のサイト マップ プロバイダと以下の構造を持つ Web.sitemap ファイルを使用します。
<siteMap> <siteMapNode title="WebForm1" description="WebForm1" url="WebForm1.aspx" > <siteMapNode title="WebForm2" description="WebForm2" url="WebForm2.aspx"/> </siteMapNode> </siteMap>
SiteMapPath コントロールを拡張し、InitializeItem メソッドをオーバーライドして新しい機能を追加するコード例を次に示します。DropDownSiteMapPath コントロールは DropDownList を現在のノードの後に追加し、現在のページの子ノードになっているページへ簡単に移動できるようにします。この例では、SiteMapNodeItemType の確認や項目を作成した後の OnItemCreated メソッドの呼び出しを含む、SiteMapNodeItem オブジェクトの使用方法を示します。
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); } }
import System.*; import System.Collections.*; import System.ComponentModel.*; import System.Web.*; import System.Web.UI.*; import 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. // public class DropDownNavigationPath extends SiteMapPath { // Override the InitializeItem method to add a PathSeparator // and DropDownList to the current node. protected void InitializeItem(SiteMapNodeItem item) { // The only node that must be handled is the CurrentNode. if (item.get_ItemType().Equals(SiteMapNodeItemType.Current)) { HyperLink hLink = new HyperLink(); // No Theming for the HyperLink. hLink.set_EnableTheming(false); // Enable the link of the SiteMapPath is enabled. hLink.set_Enabled(this.get_Enabled()); // Set the properties of the HyperLink to // match those of the corresponding SiteMapNode. hLink.set_NavigateUrl(item.get_SiteMapNode().get_Url()); hLink.set_Text(item.get_SiteMapNode().get_Title()); if (get_ShowToolTips()) { hLink.set_ToolTip(item.get_SiteMapNode().get_Description()); } // Apply styles or templates to the HyperLink here. // ... // ... // Add the item to the Controls collection. item.get_Controls().Add(hLink); AddDropDownListAfterCurrentNode(item); } else { super.InitializeItem(item); } } //InitializeItem private void AddDropDownListAfterCurrentNode(SiteMapNodeItem item) { SiteMapNodeCollection childNodes = item.get_SiteMapNode(). get_ChildNodes(); // Only do this work if there are child nodes. if (childNodes != null) { // Add another PathSeparator after the CurrentNode. SiteMapNodeItem finalSeparator = new SiteMapNodeItem(item. get_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.get_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.set_AutoPostBack(true); ddList.add_SelectedIndexChanged(new EventHandler(this. DropDownNavPathEventHandler)); // Add a ListItem to the DropDownList for every node in the // SiteMapNodes collection. for (int iCtr = 0; iCtr < childNodes.get_Count(); iCtr++) { SiteMapNode node = (SiteMapNode)childNodes.get_Item(iCtr); ddList.get_Items().Add(new ListItem(node.get_Title(), node. get_Url())); } item.get_Controls().Add(ddList); } } //AddDropDownListAfterCurrentNode // The sender is the DropDownList. public void DropDownNavPathEventHandler(Object sender, EventArgs e) { DropDownList ddL = (DropDownList)sender; // Redirect to the page the user chose. if (get_Context() != null) { get_Context().get_Response().Redirect(ddL.get_SelectedValue()); } } //DropDownNavPathEventHandler } //DropDownNavigationPath


System.Web.UI.Control
System.Web.UI.WebControls.WebControl
System.Web.UI.WebControls.CompositeControl
System.Web.UI.WebControls.SiteMapPath


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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からSiteMapPath クラスを検索する場合は、下記のリンクをクリックしてください。

- SiteMapPath クラスのページへのリンク