SiteMapNodeItem(Int32, SiteMapNodeItemType) Constructor

Definition

Initializes a new instance of the SiteMapNodeItem class, using the specified index and SiteMapNodeItemType.

C#
public SiteMapNodeItem(int itemIndex, System.Web.UI.WebControls.SiteMapNodeItemType itemType);

Parameters

itemIndex
Int32

The index in the Controls collection that the SiteMapPath control uses to track the SiteMapNodeItem object.

itemType
SiteMapNodeItemType

The functional type of SiteMapNode that this SiteMapNodeItem represents.

Examples

The following code example demonstrates how to create a SiteMapNodeItem object. This code example is part of a larger example provided for the SiteMapPath class.

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

Remarks

If the PathDirection is RootToCurrent, you can add each deeper-level item of the site navigation hierarchy at the end of the Controls collection. However, if the PathDirection property is set to CurrentToRoot, each deeper-level node must be inserted at the beginning of the Controls collection.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also