SiteMapPath クラスとは? わかりやすく解説

SiteMapPath クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

最小限ページ領域で、より簡単に Web サイト内を移動できるようにする、一連のテキストイメージハイパーリンク表示します

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

解説解説

SiteMapPath コントロールは、SiteMap オブジェクト提供されるデータ反映するサイト ナビゲーション コントロールです。このコントロールは、サイト内を簡単に移動するコンパクトな手段提供し、現在表示されているページサイト内の位置を示す基準点役割果たします。この種のコントロール一般に階層リンクなどと呼ばれますハイパーリンクページ名で階層パス表示され、これらを使用して現在の位置から階層の上位のページ直接移動できます。SiteMapDataSource。SiteMapPath は、階層構造深く、TreeView や Menu使用するページ上に必要な領域大きすぎるというサイトに有効です。

SiteMapPath コントロールは、Web サイトサイト マップ データ直接連携します。サイト マップ表されないページ上で使用した場合、このコントロール表示されません。サイト マップ詳細については、「ASP.NET サイト ナビゲーション概要」を参照してください

SiteMapPathノード構成されます。パス内の各要素ノード呼ばれ、SiteMapNodeItem オブジェクト表されます。パス終端位置定め階層ツリー基点を表すノードは、ルート ノード呼ばれます。現在表示されているページを表すノードは、現在のノード呼ばれます現在のノードルート ノードとの間にあるノード親ノードです。3 つの異なノード型の説明を以下に示します

SiteMapPath によって表示されるノードは、テンプレートスタイル適用できる HyperLink コントロールまたは Literal コントロールです。テンプレートスタイルは、次の 2 つ優先順位規則に従ってノード適用されます。

NodeStyle プロパティと NodeTemplate プロパティは、ノード型に関係なくすべてノード適用されます。これらのプロパティ両方定義されている場合は、NodeTemplate優先されます。

CurrentNodeTemplate プロパティと CurrentNodeStyle プロパティは、現在表示されているページを表すノード適用されます。CurrentNodeTemplate加えて NodeTemplate定義され場合無視されます。NodeStyleCurrentNodeStyle加えて定義され場合CurrentNodeStyleマージされ、マージされたスタイル作成されます。このマージされたスタイルでは、CurrentNodeStyleすべての要素加えCurrentNodeStyle競合しない NodeStyle追加要素使用されます。

RootNodeTemplate プロパティと RootNodeStyle プロパティは、サイト ナビゲーション階層ルートを表すノード適用されます。RootNodeTemplate加えて NodeTemplate定義され場合無視されます。NodeStyleRootNodeStyle加えて定義され場合RootNodeStyleマージされ、マージされたスタイル作成されます。このマージされたスタイルでは、RootNodeStyleすべての要素加えCurrentNodeStyle競合しない NodeStyle追加要素使用されます。最後に、現在表示されているページサイトルート ページ場合CurrentNodeTemplateCurrentNodeStyle代わりに RootNodeTemplateRootNodeStyle使用されます。

SiteMapPath コントロールは、サイト ナビゲーション情報データ ソースとして、SiteMapProvider プロパティ識別されるサイト マップ プロバイダ使用しますプロバイダ指定されない場合、SiteMap.Provider プロパティ識別される、そのサイト既定プロバイダ使用します一般に、これは ASP.NET既定サイト マップ プロバイダである XmlSiteMapProvider のインスタンスなりますサイト内で SiteMapPath コントロール使用されているが、サイト マップ プロバイダ構成されていない場合コントロールは HttpException 例外スローます。

SiteMapPath コントロールには、プログラムか利用できるイベント用意されています。これにより、イベント発生するたびにカスタム ルーチン実行されるようにできますSiteMapPath コントロールサポートされイベントの一覧を次の表に示します

イベント

説明

ItemCreated

SiteMapPath コントロール最初に SiteMapNodeItem作成し、SiteMapNode に関連付けたときに発生します

ItemDataBound

SiteMapNodeItemSiteMapNode格納されているサイト マップ データバインドされたときに発生します

SiteMapPath から派生したクラスは、InitializeItem メソッドオーバーライドして、ナビゲーション コントロール格納されている SiteMapNodeItem コントロールカスタマイズます。完全に制御するために SiteMapNodeItem オブジェクト作成し、CreateControlHierarchy メソッドオーバーライドする SiteMapPath 派生クラス追加します

ユーザー補助

使用例使用例

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
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.Control
     System.Web.UI.WebControls.WebControl
       System.Web.UI.WebControls.CompositeControl
        System.Web.UI.WebControls.SiteMapPath
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からSiteMapPath クラスを検索した結果を表示しています。
Weblioに収録されているすべての辞書からSiteMapPath クラスを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からSiteMapPath クラス を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「SiteMapPath クラス」の関連用語

SiteMapPath クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



SiteMapPath クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS