SiteMapNodeCollection.Item[Int32] Property

Definition

Gets or sets the SiteMapNode object at the specified index in the collection.

C#
public virtual System.Web.SiteMapNode this[int index] { get; set; }

Parameters

index
Int32

The index of the SiteMapNode to find.

Property Value

A SiteMapNode that represents an element in the SiteMapNodeCollection.

Exceptions

index is less than zero.

-or-

index is great than the Count.

The value supplied to the setter is null.

Examples

The following code example demonstrates how to use the Item[] indexer to retrieve a SiteMapNode object from the SiteMapNodeCollection collection. In this example, a SiteMapNode object is removed from its position at the second element of the internal array using the Remove method and is appended to the array with the Add method. To insert a SiteMapNode object at a specific index, instead of appending it to the end of the array, use the Insert method.

C#

// Move a node from one spot in the list to another.
try {
    Response.Write("Original node order: <BR>");
    foreach (SiteMapNode node in nodes) {
        Response.Write( node.Title + "<BR>");
    }
    SiteMapNode aNode = nodes[1];

    Response.Write("Adding " + aNode.Title + " to the end of the collection.<BR>");
    nodes.Add(aNode);

    Response.Write("Removing " + aNode.Title + " at position 1. <BR>");
    nodes.Remove(nodes[1]);

    Response.Write("New node order: <BR>");
    foreach (SiteMapNode node in nodes) {
        Response.Write( node.Title + "<BR>");
    }
}
catch (NotSupportedException nse) {
    Response.Write("NotSupportedException caught.<BR>");
}

Remarks

You can use the Item[] indexer to iterate over the contents of a SiteMapNodeCollection collection or to replace the SiteMapNode object at a specified index.

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