SiteMapProvider.GetParentNode(SiteMapNode) 메서드

정의

파생 클래스에서 재정의되면 특정 SiteMapNode 개체의 부모 노드를 검색합니다.

public:
 abstract System::Web::SiteMapNode ^ GetParentNode(System::Web::SiteMapNode ^ node);
public abstract System.Web.SiteMapNode GetParentNode (System.Web.SiteMapNode node);
abstract member GetParentNode : System.Web.SiteMapNode -> System.Web.SiteMapNode
Public MustOverride Function GetParentNode (node As SiteMapNode) As SiteMapNode

매개 변수

node
SiteMapNode

부모 노드를 검색할 SiteMapNode입니다.

반환

SiteMapNode

node의 부모 노드를 나타내는 SiteMapNode이거나, 그렇지 않고 SiteMapNode에 부모 노드가 없거나 보안 트리밍이 설정되어 있으며 현재 사용자가 부모 노드에 액세스할 수 없으면 null입니다.

참고: GetParentNode(SiteMapNode) 부모 노드가 다른 공급자에 속하는 경우에도 반환 null 될 수 있습니다. 이 경우 nodeParentNode 속성을 대신 사용합니다.

예제

다음 코드 예제를 구현 하는 방법에 설명 합니다 GetParentNode 메서드를 구현 하는 클래스에서 SiteMapProvider 클래스입니다. 합니다 SimpleTextSiteMapProvider 간의 부모/자식 계층 관계를 저장 SiteMapNode 개체를 IList 인터페이스와 같은 ArrayList 개체입니다.

이 코드 예제는에 대해 제공 된 큰 예제의 일부는 SiteMapProvider 클래스입니다.

// 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;
}
' Implement the GetChildNodes method.
Public Overrides Function GetChildNodes(ByVal node As SiteMapNode) As SiteMapNodeCollection
  Dim children As New SiteMapNodeCollection()
  ' Iterate through the ArrayList and find all nodes that have the specified node as a parent.
  SyncLock Me
    Dim i As Integer
    For i = 0 To childParentRelationship.Count - 1

      Dim de As DictionaryEntry = CType(childParentRelationship(i), DictionaryEntry)
      Dim nodeUrl As String = CType(de.Key, String)

      Dim parent As SiteMapNode = GetNode(childParentRelationship, nodeUrl)

      If Not (parent Is Nothing) AndAlso node.Url = parent.Url Then
        ' The SiteMapNode with the Url that corresponds to nodeUrl
        ' is a child of the specified node. Get the SiteMapNode for
        ' the nodeUrl.
        Dim child As SiteMapNode = FindSiteMapNode(nodeUrl)
        If Not (child Is Nothing) Then
          children.Add(CType(child, SiteMapNode))
        Else
          Throw New Exception("ArrayLists not in sync.")
        End If
      End If
    Next i
  End SyncLock
  Return children
End Function 'GetChildNodes

Protected Overrides Function GetRootNodeCore() As SiteMapNode
  Return RootNode
End Function ' GetRootNodeCore()

' Implement the GetParentNode method.
Public Overrides Function GetParentNode(ByVal node As SiteMapNode) As SiteMapNode
  ' Check the childParentRelationship table and find the parent of the current node.
  ' If there is no parent, the current node is the RootNode.
  Dim parent As SiteMapNode = Nothing
  SyncLock Me
    ' Get the Value of the node in childParentRelationship
    parent = GetNode(childParentRelationship, node.Url)
  End SyncLock
  Return parent
End Function 'GetParentNode

적용 대상

추가 정보