SiteMapPath.InitializeItem(SiteMapNodeItem) 方法

定義

填入 (Populate) 表示 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 來判斷專案所代表之節點的功能類型,並套用針對該節點類型定義的任何範本或樣式。

如果 具有 Root 專案類型,則會 HyperLink 建立子控制項,並套用 和 RootNodeTemplate RootNodeStyleSiteMapNodeItem RootNodeTemplate如果 已設定 ,則會將其 ITemplate 套用至節點。 RootNodeStyle相反地,它會與任何已定義 NodeStyle 和套用的 合併。 最後,如果未定義任何範本或樣式,則會建立基本 HyperLink 控制項,並使用節點中的值初始化。

SiteMapNodeItem如果 具有 Current 專案類型, Literal 則會根據 的 RenderCurrentNodeAsLink 傳回值建立 或 HyperLink 子控制項。 CurrentNodeTemplate然後可以套用 或 CurrentNodeStyleCurrentNodeTemplate如果 已設定 ,則會將其 ITemplate 套用至節點。 如果改為 CurrentNodeStyle 設定 ,則會與任何已定義 NodeStyle 和套用的 合併。

SiteMapNodeItem如果 具有 Parent 專案類型,則會 HyperLink 建立子控制項,並 NodeTemplate 套用 和 NodeStyleNodeTemplate如果 已設定 ,則會將其 ITemplate 套用至節點。 如果改為 NodeStyle 設定 ,則會套用它。

最後,如果 SiteMapNodeItem 具有專案類型,則會 Literal 建立子控制項,並根據 PathSeparatorTemplate 針對節點類型定義的相同一 Parent 般規則來套用 和 PathSeparatorStyle PathSeparator

InitializeItem覆寫 方法來操作個別 SiteMapNodeItem 物件。 如果類別的設計需要更廣泛的控制物件 SiteMapNodeItem 如何建立及新增至 SiteMapPath 控制項,請覆寫 CreateControlHierarchy 方法。

適用於

另請參閱