Export (0) Print
Expand All

SiteMapNodeCollection.Item Property

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

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

public virtual SiteMapNode this[
	int index
] { get; set; }

Parameters

index
Type: System.Int32

The index of the SiteMapNode to find.

Property Value

Type: System.Web.SiteMapNode
A SiteMapNode that represents an element in the SiteMapNodeCollection.

ExceptionCondition
NotSupportedException

The SiteMapNodeCollection is read-only.

ArgumentOutOfRangeException

index is less than zero.

- or -

index is great than the Count.

ArgumentNullException

The value supplied to the setter is null.

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.

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.


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

.NET Framework

Supported in: 4.5.3, 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