IHierarchyData.Type Property
.NET Framework 3.0
Gets the name of the type of Object contained in the Item property.
Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)
Assembly: System.Web (in system.web.dll)
The Type property does not return the System.Type of the object represented in an IHierarchyData object. It returns a name used by data-bound controls to differentiate between items in a hierarchy that have different bindable properties.
The following code example demonstrates how to write the basic IHierarchyData properties to an HttpResponse stream, then 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 />";
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
Community Additions
ADD
Show: