IHierarchyData.GetChildren Method

Gets an enumeration object that represents all the child nodes of the current hierarchical node.

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)

IHierarchicalEnumerable^ GetChildren ()
IHierarchicalEnumerable GetChildren ()
function GetChildren () : IHierarchicalEnumerable
Not applicable.

Return Value

An IHierarchicalEnumerable collection of child nodes of the current hierarchical node.

You can use the HasChildren property to determine whether the IHierarchyData node has child nodes.

The following code example demonstrates how to check the HasChildren property to determine whether the current hierarchical data node has child nodes, and retrieve them using the GetChildren method. This code example is part of a larger example provided for the IHierarchyData interface.

No code example is currently available or this language may not be supported.
// Print out the the current data node, then iterate through its
// children and do the same.
private void PrintFullChildNodeInfo(IHierarchyData node)
{
    String whitespace = "     ";
    String br = "<br />";

    get_Response().Write(node.toString() + br);
    get_Response().Write(whitespace + node.get_Path() + br);

    // Check for specific types and perform extended functions.
    if (node.get_Type().Equals("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 = null;

        siteNode = (SiteMapNode)node.get_Item();
        get_Response().Write(whitespace + siteNode.get_Url() + br);
        get_Response().Write(whitespace + siteNode.get_Description() + br);
    }
    else {
        if (node.get_Type().Equals("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.get_HasChildren()) {
        IEnumerator children = 
            ((IHierarchicalEnumerable)node.GetChildren()).GetEnumerator();

        while (children.MoveNext()) {
            // Print out SiteMapNode Titles recursively.
            IHierarchyData hierarchicalNode = 
                node.GetChildren().GetHierarchyData(children.get_Current());
            PrintFullChildNodeInfo(hierarchicalNode);
        }
    }
}//PrintFullChildNodeInfo

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show: