Export (0) Print
Expand All

SiteMapPath.InitializeItem Method

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.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

protected virtual void InitializeItem(
	SiteMapNodeItem item
)

Parameters

item
Type: System.Web.UI.WebControls.SiteMapNodeItem

The SiteMapNodeItem to initialize.

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.

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);
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft