แก้ไข

แชร์ผ่าน


SiteMapPath.InitializeItem(SiteMapNodeItem) Method

Definition

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.

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)

Parameters

item
SiteMapNodeItem

The SiteMapNodeItem to initialize.

Examples

The following code example demonstrates how to override the InitializeItem method to add functionality to a control that derives from SiteMapPath. This code example is part of a larger example provided for the SiteMapPath class.

// 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

Remarks

The InitializeItem method determines the functional type of node that the item represents by checking the SiteMapNodeItemType, and applies any templates or styles that are defined for that kind of node.

If the SiteMapNodeItem has a Root item type, a HyperLink child control is created, and the RootNodeTemplate and RootNodeStyle may be applied. If the RootNodeTemplate is set, its ITemplate is applied to the node. In instead the RootNodeStyle is set, it is merged with any defined NodeStyle and applied. Finally, if no templates or styles are defined, a basic HyperLink control is created and initialized with values from the node.

If the SiteMapNodeItem has a Current item type, either a Literal or HyperLink child control is created, depending on the return value of RenderCurrentNodeAsLink. Then either the CurrentNodeTemplate or CurrentNodeStyle may be applied. If the CurrentNodeTemplate is set, its ITemplate is applied to the node. If instead the CurrentNodeStyle is set, it is merged with any defined NodeStyle and applied.

If the SiteMapNodeItem has a Parent item type, a HyperLink child control is created and the NodeTemplate and NodeStyle may be applied. If the NodeTemplate is set, its ITemplate is applied to the node. If instead the NodeStyle is set, it is applied.

Finally, if the SiteMapNodeItem has a PathSeparator item type, a Literal child control is created and the PathSeparatorTemplate and PathSeparatorStyle are applied according to the same general rules defined for a Parent node type.

Override the InitializeItem method to manipulate individual SiteMapNodeItem objects. If the design of the class requires more extensive control over how the SiteMapNodeItem objects are created and added to the SiteMapPath control, override the CreateControlHierarchy method.

Applies to

See also