SiteMapProvider.GetChildNodes(SiteMapNode) Metoda

Definicja

Po przesłonięciu w klasie pochodnej pobiera węzły podrzędne określonego SiteMapNodeelementu .

C#
public abstract System.Web.SiteMapNodeCollection GetChildNodes(System.Web.SiteMapNode node);

Parametry

node
SiteMapNode

Element SiteMapNode , dla którego mają być pobierane wszystkie węzły podrzędne.

Zwraca

Tylko SiteMapNodeCollection do odczytu, który zawiera natychmiastowe węzły podrzędne określonego SiteMapNode; w przeciwnym razie null lub pustą kolekcję, jeśli nie istnieją żadne węzły podrzędne.

Przykłady

W poniższym przykładzie kodu pokazano, jak zaimplementować metodę GetChildNodes w klasie, która implementuje klasę abstrakcyjną SiteMapProvider . Obiekt SimpleTextSiteMapProvider przechowuje hierarchiczne relacje nadrzędne/podrzędne w jednym Hashtable obiekcie i we wszystkich SiteMapNode obiektach w innym. Metoda GetChildNodes wykonuje wyszukiwanie odwrotne przy użyciu obu ArrayList obiektów.

Ten przykład kodu jest częścią większego przykładu udostępnionego SiteMapProvider dla klasy .

C#
// Implement the GetChildNodes method.
public override SiteMapNodeCollection GetChildNodes(SiteMapNode node)
{
  SiteMapNodeCollection children = new SiteMapNodeCollection();
  // Iterate through the ArrayList and find all nodes that have the specified node as a parent.
  lock (this)
  {
    for (int i = 0; i < childParentRelationship.Count; i++)
    {

      string nodeUrl = ((DictionaryEntry)childParentRelationship[i]).Key as string;

      SiteMapNode parent = GetNode(childParentRelationship, nodeUrl);

      if (parent != null && node.Url == parent.Url)
      {
        // The SiteMapNode with the Url that corresponds to nodeUrl
        // is a child of the specified node. Get the SiteMapNode for
        // the nodeUrl.
        SiteMapNode child = FindSiteMapNode(nodeUrl);
        if (child != null)
        {
          children.Add(child as SiteMapNode);
        }
        else
        {
          throw new Exception("ArrayLists not in sync.");
        }
      }
    }
  }
  return children;
}
protected override SiteMapNode GetRootNodeCore()
{
  return RootNode;
}
// Implement the GetParentNode method.
public override SiteMapNode GetParentNode(SiteMapNode node)
{
  // Check the childParentRelationship table and find the parent of the current node.
  // If there is no parent, the current node is the RootNode.
  SiteMapNode parent = null;
  lock (this)
  {
    // Get the Value of the node in childParentRelationship
    parent = GetNode(childParentRelationship, node.Url);
  }
  return parent;
}

Uwagi

Klasy pochodzące z SiteMapProvider klasy muszą implementować metodę abstrakcyjną GetChildNodes .

Uwagi dotyczące implementowania

Podczas zastępowania GetChildNodes(SiteMapNode) metody w klasie pochodnej należy wykonać przycinanie zabezpieczeń w węzłach podrzędnych i upewnić się, że zwracana kolekcja jest tylko do odczytu. Kolekcja zawiera tylko bezpośrednie elementy podrzędne określonego nodeelementu .

Dotyczy

Produkt Wersje
.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

Zobacz też