This documentation is archived and is not being maintained.

SiteMapPath.InitializeItem Method

Note: This method is new in the .NET Framework version 2.0.

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
)
protected void InitializeItem (
	SiteMapNodeItem item
)
protected function InitializeItem (
	item : SiteMapNodeItem
)

Parameters

item

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

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

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0
Show: