Export (0) Print
Expand All

IHierarchyData.Item Property

Gets the hierarchical data node that the IHierarchyData object represents.

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

Object Item { get; }

Property Value

Type: System.Object
An Object hierarchical data node object.

While many classes that represent hierarchical data nodes, such as the SiteMapNode class, implement the IHierarchyData interface directly, other classes only act as a wrapper for a class that does not implement the interface. The Item property is provided for these design situations, when business objects are functionally equivalent to an IHierarchyData object but cannot be redesigned easily.

The following code example demonstrates how to access IHierarchyData properties, check the type of an IHierarchyData object using the Type property, and cast the object to perform more type-specific operations. This code example is part of a larger example provided for the IHierarchyData interface.

// 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>";

    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);
        }
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft