SiteMapNodeCollection.Item Property (Int32)
Gets or sets the SiteMapNode object at the specified index in the collection.
Assembly: System.Web (in System.Web.dll)
Parameters
- index
-
Type:
System.Int32
The index of the SiteMapNode to find.
Property Value
Type: System.Web.SiteMapNodeA SiteMapNode that represents an element in the SiteMapNodeCollection.
| Exception | Condition |
|---|---|
| NotSupportedException | The SiteMapNodeCollection is read-only. |
| ArgumentOutOfRangeException | |
| 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>") Dim node As SiteMapNode For Each node In nodes Response.Write( node.Title & "<BR>") Next Dim aNode As SiteMapNode = 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>") For Each node In nodes Response.Write( node.Title & "<BR>") Next Catch nse As NotSupportedException Response.Write("NotSupportedException caught.<BR>") End Try
Available since 2.0