SiteMapPath.InitializeItem(SiteMapNodeItem) メソッド

定義

SiteMapNodeItem を表す Web サーバー コントロールの SiteMapNode に、ノードの機能およびノードに指定したテンプレートとスタイルに基づいて一連の子コントロールを読み込みます。

protected:
 virtual void InitializeItem(System::Web::UI::WebControls::SiteMapNodeItem ^ item);
protected virtual void InitializeItem (System.Web.UI.WebControls.SiteMapNodeItem item);
abstract member InitializeItem : System.Web.UI.WebControls.SiteMapNodeItem -> unit
override this.InitializeItem : System.Web.UI.WebControls.SiteMapNodeItem -> unit
Protected Overridable Sub InitializeItem (item As SiteMapNodeItem)

パラメーター

item
SiteMapNodeItem

初期化する SiteMapNodeItem

次のコード例では、メソッドをオーバーライド InitializeItem して、派生 SiteMapPath元のコントロールに機能を追加する方法を示します。 このコード例は、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);
    }
}
' 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 、項目が表すノードの機能の種類を SiteMapNodeItemType確認して決定し、その種類のノードに対して定義されているすべてのテンプレートまたはスタイルを適用します。

項目の SiteMapNodeItem 種類がある Root 場合は、 HyperLink 子コントロールが作成され RootNodeTemplate 、適用 RootNodeStyle される可能性があります。 が設定されている RootNodeTemplate 場合は、ノード ITemplate に適用されます。 代わりに設定され RootNodeStyle 、定義 NodeStyle された任意の設定とマージされ、適用されます。 最後に、テンプレートまたはスタイルが定義されていない場合は、基本 HyperLink コントロールが作成され、ノードの値で初期化されます。

項目のSiteMapNodeItem種類があるCurrent場合は、Literal戻り値RenderCurrentNodeAsLinkに応じて、a またはHyperLink子コントロールが作成されます。 次に、いずれかをCurrentNodeTemplateCurrentNodeStyle適用してもよい。 が設定されている CurrentNodeTemplate 場合は、ノード ITemplate に適用されます。 代わりに設定されている CurrentNodeStyle 場合は、定義された任意の設定 NodeStyle とマージされ、適用されます。

項目のSiteMapNodeItem種類があるParent場合は、HyperLink子コントロールが作成され、NodeTemplateNodeStyle適用される可能性があります。 が設定されている NodeTemplate 場合は、ノード ITemplate に適用されます。 代わりに設定されている NodeStyle 場合は、適用されます。

最後に、項目の種類がある場合SiteMapNodeItemPathSeparator、子コントロールが作成され、Literalノードの種類に定義ParentされているのとPathSeparatorTemplatePathSeparatorStyle同じ一般的な規則に従って適用されます。

メソッドを InitializeItem オーバーライドして個々 SiteMapNodeItem のオブジェクトを操作します。 クラスの設計で、オブジェクトの作成方法とコントロールへの追加方法 SiteMapNodeItem をより広範に制御する SiteMapPath 必要がある場合は、メソッドをオーバーライドします CreateControlHierarchy

適用対象

こちらもご覧ください