Export (0) Print
Expand All
2 out of 14 rated this helpful - Rate this topic

IHierarchicalDataSource Interface

Represents a hierarchical data source that hierarchical data-bound controls such as TreeView can bind to.

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)
public interface IHierarchicalDataSource
public interface IHierarchicalDataSource
public interface IHierarchicalDataSource
Not applicable.

ASP.NET supports a control data-binding architecture that enables Web server controls to bind to data and present it in a consistent fashion. Web server controls that bind to data are called data-bound controls, and the classes that facilitate binding are called data source controls. Data source controls can represent any data source: a file, a stream, a relational database, a business object, and so on. Data source controls present data in a consistent way to data-bound controls, regardless of the source or format of the underlying data.

Data source controls that represent hierarchical data derive from the HierarchicalDataSourceControl class, which is the base ASP.NET implementation of the IHierarchicalDataSource interface. The IHierarchicalDataSource interface is used to define data source controls that expose hierarchical data, rather than tabular or list-style data, to Web server controls that derive from the HierarchicalDataBoundControl class, such as the TreeView control. The interface defines a single method, GetHierarchicalView, which retrieves a strongly typed HierarchicalDataSourceView object. Data source controls that implement this interface support a hierarchical view for each hierarchical level of data they represent. The data source views are not named, like DataSourceView objects, but are identified by their unique hierarchical path, which is the viewPath parameter passed to the GetHierarchicalView method.

You can think of a data source control as the combination of the IHierarchicalDataSource object and its associated views on the underlying data. Each associated HierarchicalDataSourceView object defines the capabilities of a data source control for the hierarchical level represented, and, like all ASP.NET data source view objects, performs operations such as insert, update, delete, and sort.

Data source controls that expose only hierarchical data, such as SiteMapDataSource, are derived from the HierarchicalDataSourceControl class. Other data source controls that expose their data as both hierarchical data and tabular data, such as XmlDataSource, are derived from HierarchicalDataSourceControl but implement the IDataSource and IListSource interfaces.

The following code example demonstrates how to extend the abstract HierarchicalDataSourceControl class, which implements the IHierarchicalDataSource interface, to create a data source control that displays file system information. The FileSystemDataSource class provides an implementation of the GetHierarchicalView method, which retrieves a strongly typed view object for a specified file system path. This code example is part of a larger example provided for the HierarchicalDataSourceControl class.

using System;
using System.Collections;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

[AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
public class FileSystemDataSource : HierarchicalDataSourceControl, IHierarchicalDataSource
{
    public FileSystemDataSource() : base() {}

    // Return a strongly typed view for the current data source control.
    private FileSystemDataSourceView view = null;
    protected override HierarchicalDataSourceView GetHierarchicalView(string viewPath) {
        if (null == view) {
            view = new FileSystemDataSourceView(viewPath);
        }
        return view;
    }

    // The FileSystemDataSource can be used declaratively. To enable
    // declarative use, override the default implementation of
    // CreateControlCollection to return a ControlCollection that
    // you can add to.
    protected override ControlCollection CreateControlCollection() {
        return new ControlCollection(this);
    }
}

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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.