SiteMapNodeCollection.IndexOf Method (SiteMapNode)

 

Searches for the specified SiteMapNode object, and then returns the zero-based index of the first occurrence within the entire collection.

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

public virtual int IndexOf(
	SiteMapNode value
)

Parameters

value
Type: System.Web.SiteMapNode

The SiteMapNode to locate in the SiteMapNodeCollection.

Return Value

Type: System.Int32

The zero-based index of the first occurrence of value within the entire SiteMapNodeCollection, if found; otherwise, -1.

The IndexOf method determines equality by calling the Object.Equals method.

The following code example demonstrates how to use the Contains and IndexOf methods of the SiteMapNodeCollection class. The code checks two providers, AspNetXmlSiteMapProvider and MyXmlSiteMapProvider, for child nodes of the root node that are duplicates.

String providername1 = "AspNetXmlSiteMapProvider";
String providername2 = "MyXmlSiteMapProvider";
SiteMapProviderCollection providers = SiteMap.Providers;

if (providers[providername1] != null && providers[providername2] != null)
{
  SiteMapProvider provider1 = providers[providername1];
  SiteMapProvider provider2 = providers[providername2];
  SiteMapNodeCollection collection1 = provider1.RootNode.ChildNodes;
  SiteMapNodeCollection collection2 = provider2.RootNode.ChildNodes;
  int matches = 0;
  foreach (SiteMapNode node in collection1)
  {
    if (collection2.Contains(node))
    {
      Response.Write("Match found at " +
        providername1 + ", index = " +
        collection1.IndexOf(node) + " with " +
        providername2 + ", index = " +
        collection2.IndexOf(node) + ".<br />");
      matches++;
    }
  }
  Response.Write("Number of matches found = " +
    matches.ToString() + ".");
}
else
{
  Response.Write(providername1 + " or " +
    providername2 + " not found.");
}

.NET Framework
Available since 2.0
Return to top
Show: