SiteMapPath.OnItemCreated Method

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

Raises the ItemCreated event of the SiteMapPath control.

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

protected virtual void OnItemCreated (
	SiteMapNodeItemEventArgs e
)
protected void OnItemCreated (
	SiteMapNodeItemEventArgs e
)
protected function OnItemCreated (
	e : SiteMapNodeItemEventArgs
)

Parameters

e

A SiteMapNodeItemEventArgs that contains event data.

The ItemCreated event is raised after the SiteMapPath control creates a SiteMapNodeItem, which is a Web server control that represents a SiteMapNode, and associates it to a SiteMapNode. The OnItemCreated method is called before the created node item is bound to its data. This allows you to provide an event-handling method that performs a custom routine whenever a SiteMapNodeItem is created.

Raising an event invokes the event handler through a delegate. For more information, see Raising an Event.

The OnItemCreated method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

Notes to Inheritors When overriding OnItemCreated in a derived class, be sure to call the base class's OnItemCreated method so that registered delegates receive the event.

The following code example demonstrates how to call the OnItemCreated method after creating a SiteMapNodeItem within the InitializeItem method. This code example is part of a larger example provided for the SiteMapPath class.

private void AddDropDownListAfterCurrentNode(SiteMapNodeItem item) {

    SiteMapNodeCollection childNodes = item.SiteMapNode.ChildNodes;

    // Only do this work if there are child nodes.
    if (childNodes != null) {

        // Add another PathSeparator after the CurrentNode.
        SiteMapNodeItem finalSeparator =
            new SiteMapNodeItem(item.ItemIndex,
                                SiteMapNodeItemType.PathSeparator);

        SiteMapNodeItemEventArgs eventArgs =
            new SiteMapNodeItemEventArgs(finalSeparator);

        InitializeItem(finalSeparator);
        // Call OnItemCreated every time a SiteMapNodeItem is
        // created and initialized.
        OnItemCreated(eventArgs);

        // The pathSeparator does not bind to any SiteMapNode, so
        // do not call DataBind on the SiteMapNodeItem.
        item.Controls.Add(finalSeparator);

        // Create a DropDownList and populate it with the children of the
        // CurrentNode. There are no styles or templates that are applied
        // to the DropDownList control. If OnSelectedIndexChanged is raised,
        // the event handler redirects to the page selected.
        // The CurrentNode has child nodes.
        DropDownList ddList = new DropDownList();
        ddList.AutoPostBack = true;

        ddList.SelectedIndexChanged += new EventHandler(this.DropDownNavPathEventHandler);

        // Add a ListItem to the DropDownList for every node in the
        // SiteMapNodes collection.
        foreach (SiteMapNode node in childNodes) {
            ddList.Items.Add(new ListItem(node.Title, node.Url));
        }

        item.Controls.Add(ddList);
    }
}

private void AddDropDownListAfterCurrentNode(SiteMapNodeItem item)
{
    SiteMapNodeCollection childNodes = item.get_SiteMapNode().
        get_ChildNodes();
    // Only do this work if there are child nodes.
    if (childNodes != null) {
        // Add another PathSeparator after the CurrentNode.
        SiteMapNodeItem finalSeparator = new SiteMapNodeItem(item.
            get_ItemIndex(), SiteMapNodeItemType.PathSeparator);

        SiteMapNodeItemEventArgs eventArgs = new SiteMapNodeItemEventArgs(
            finalSeparator);

        InitializeItem(finalSeparator);
        // Call OnItemCreated every time a SiteMapNodeItem is
        // created and initialized.
        OnItemCreated(eventArgs);
        // The pathSeparator does not bind to any SiteMapNode, so 
        // do not call DataBind on the SiteMapNodeItem.
        item.get_Controls().Add(finalSeparator);
        // Create a DropDownList and populate it with the children of the 
        // CurrentNode. There are no styles or templates that are applied
        // to the DropDownList control. If OnSelectedIndexChanged is raised, 
        // the event handler redirects to the page selected.
        // The CurrentNode has child nodes.
        DropDownList ddList = new DropDownList();
        ddList.set_AutoPostBack(true);

        ddList.add_SelectedIndexChanged(new EventHandler(this.
            DropDownNavPathEventHandler));
        // Add a ListItem to the DropDownList for every node in the
        // SiteMapNodes collection.
        for (int iCtr = 0; iCtr < childNodes.get_Count(); iCtr++) {
            SiteMapNode node = (SiteMapNode)childNodes.get_Item(iCtr);
            ddList.get_Items().Add(new ListItem(node.get_Title(), node.
                get_Url()));
        }

        item.get_Controls().Add(ddList);
    }
} //AddDropDownListAfterCurrentNode

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

Community Additions

ADD
Show: