다음을 통해 공유


IHierarchyData.GetChildren 메서드

정의

현재 계층적 노드의 모든 자식 노드를 나타내는 열거형 개체를 가져옵니다.

public:
 System::Web::UI::IHierarchicalEnumerable ^ GetChildren();
public System.Web.UI.IHierarchicalEnumerable GetChildren ();
abstract member GetChildren : unit -> System.Web.UI.IHierarchicalEnumerable
Public Function GetChildren () As IHierarchicalEnumerable

반환

IHierarchicalEnumerable

현재 계층적 노드의 자식 노드를 나타내는 IHierarchicalEnumerable 컬렉션입니다.

예제

다음 코드 예제를 확인 하는 방법에 설명 합니다 HasChildren 속성을 현재 계층적 데이터 노드에 자식 노드가 있는지 여부를 확인 하 고 검색 사용 하 여는 GetChildren 메서드. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 IHierarchyData 인터페이스입니다.

// Print out the current data node, then iterate through its
// children and do the same.
private void PrintFullChildNodeInfo(IHierarchyData node)
{
    string whitespace = "     ";
    string br = "<BR>";

    Response.Write(node.ToString() + br);
    Response.Write(whitespace + node.Path + br);

    // Check for specific types and perform extended functions.
    if (node.Type == "SiteMapNode")
    {
        // Because SiteMapNode implements the IHierarchyData interface,
        // the IHierarchyData object can be cast directly as a SiteMapNode,
        // rather than accessing the Item property for the object that
        // the Type property identifies.
        SiteMapNode siteNode = node.Item as SiteMapNode;
        Response.Write(whitespace + siteNode.Url + br);
        Response.Write(whitespace + siteNode.Description + br);
    }
    else if (node.Type == "SomeBusinessObject")
    {
        // If the IHierarchyData instance is a wrapper class on a business
        // object of some kind, you can retrieve the business object by using
        // the IHierarchyData.Item property.
        //          SomeBusinessObject busObj = node.Item as SomeBusinessObject;
    }

    if (node.HasChildren)
    {
        IEnumerator children = ((IHierarchicalEnumerable)node.GetChildren()).GetEnumerator();

        while (children.MoveNext())
        {
            // Print out SiteMapNode Titles recursively.
            IHierarchyData hierarchicalNode = node.GetChildren().GetHierarchyData(children.Current);
            PrintFullChildNodeInfo(hierarchicalNode);
        }
    }
}
' Print out the current data node, then iterate through its
' children and do the same.

Private Sub PrintFullChildNodeInfo(ByVal node As IHierarchyData)
    Dim whitespace As String = "     "
    Dim br As String = "<BR>"

    Response.Write(Convert.ToString(node) & br)
    Response.Write(whitespace & node.Path & br)

    ' Check for specific types and perform extended functions.
    If node.Type = "SiteMapNode" Then
        ' Because SiteMapNode implements the IHierarchyData interface,
        ' the IHierarchyData object can be cast directly as a SiteMapNode,
        ' rather than accessing the Item property for the object that
        ' the Type property identifies.
        Dim siteNode As SiteMapNode = CType(node.Item, SiteMapNode)
        Response.Write(whitespace & siteNode.Url & br)
        Response.Write(whitespace & siteNode.Description & br)

    ElseIf node.Type = "SomeBusinessObject Then" Then
        ' If the IHierarchyData instance is a wrapper class on a business
        ' object of some kind, you can retrieve the business object by using
        ' the IHierarchyData.Item property.
        '          SomeBusinessObject busObj = node.Item as SomeBusinessObject;
    End If

    If node.HasChildren Then
        Dim children As IEnumerator = CType(node.GetChildren().GetEnumerator(), IHierarchicalEnumerable)
        While children.MoveNext()
            ' Print out SiteMapNode Titles recursively.
            Dim hierarchicalNode As IHierarchyData = node.GetChildren().GetHierarchyData(children.Current)
            PrintFullChildNodeInfo(hierarchicalNode)
        End While
    End If
End Sub

설명

사용할 수는 HasChildren 속성을 확인 여부를 IHierarchyData 자식 노드가 합니다.

적용 대상

추가 정보