IHierarchicalDataSource 接口

定义

表示分层数据绑定控件(如 TreeView)可以绑定到的分层数据源。Represents a hierarchical data source that hierarchical data-bound controls such as TreeView can bind to.

public interface class IHierarchicalDataSource
public interface IHierarchicalDataSource
type IHierarchicalDataSource = interface
Public Interface IHierarchicalDataSource
派生

示例

下面的代码示例演示如何扩展用于HierarchicalDataSourceControl IHierarchicalDataSource实现接口的抽象类, 以创建显示文件系统信息的数据源控件。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. 类提供GetHierarchicalView方法的实现, 该方法为指定的文件系统路径检索强类型化视图对象。 FileSystemDataSourceThe FileSystemDataSource class provides an implementation of the GetHierarchicalView method, which retrieves a strongly typed view object for a specified file system path. 此代码示例是为HierarchicalDataSourceControl类提供的更大示例的一部分。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;

public class FileSystemDataSource :
    HierarchicalDataSourceControl, IHierarchicalDataSource
{
    private FileSystemDataSourceView view = null;

    public FileSystemDataSource() : base() { }

    protected override HierarchicalDataSourceView
        GetHierarchicalView(string viewPath)
    {
        view = new FileSystemDataSourceView(viewPath);
        return view;
    }
}
Imports System.Collections
Imports System.IO
Imports System.Runtime.InteropServices
Imports System.Security.Permissions
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace Samples.AspNet

    Public Class FileSystemDataSource
        Inherits HierarchicalDataSourceControl

        Public Sub New()
        End Sub

        Private view As FileSystemDataSourceView = Nothing

        Protected Overrides Function GetHierarchicalView( _
            ByVal viewPath As String) As HierarchicalDataSourceView

            view = New FileSystemDataSourceView(viewPath)
            Return view
        End Function

    End Class

注解

ASP.NET 支持控件数据绑定体系结构, 该体系结构使 Web 服务器控件可以绑定到数据并以一致的方式呈现数据。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 服务器控件称为数据绑定控件, 便于绑定的类称为数据源控件。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.

表示分层数据的数据源控件派生自HierarchicalDataSourceControl类, 该类是IHierarchicalDataSource接口的基 ASP.NET 实现。Data source controls that represent hierarchical data derive from the HierarchicalDataSourceControl class, which is the base ASP.NET implementation of the IHierarchicalDataSource interface. 接口用于定义数据源控件, 这些控件向派生HierarchicalDataBoundControlTreeView类的 Web 服务器控件 (例如控件) 公开分层数据, 而不是表格或列表样式数据。 IHierarchicalDataSourceThe 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. 接口定义一个方法, GetHierarchicalView该方法检索强类型HierarchicalDataSourceView对象。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. 数据源视图未命名, 如DataSourceView对象, 但由其唯一分层路径标识, 后者viewPath是传递给GetHierarchicalView方法的参数。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.

您可以将数据源控件视为该IHierarchicalDataSource对象及其关联视图在基础数据上的组合。You can think of a data source control as the combination of the IHierarchicalDataSource object and its associated views on the underlying data. 每个HierarchicalDataSourceView关联的对象都为所表示的层次结构级别定义数据源控件的功能, 并与所有 ASP.NET 数据源视图对象一样, 执行插入、更新、删除和排序等操作。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.

仅公开分层数据的数据源控件 (如SiteMapDataSource) 是HierarchicalDataSourceControl从类派生的。Data source controls that expose only hierarchical data, such as SiteMapDataSource, are derived from the HierarchicalDataSourceControl class. 同时公开其数据作为层次结构数据和表格数据的其他数据源控件 (如XmlDataSource) 派生自HierarchicalDataSourceControl , 但实现IDataSourceIListSource接口。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.

方法

GetHierarchicalView(String)

获取指定路径的 IHierarchicalDataSource 接口的视图帮助器对象。Gets the view helper object for the IHierarchicalDataSource interface for the specified path.

事件

DataSourceChanged

IHierarchicalDataSource 接口表示的数据存储已更改时发生。Occurs when the data storage that the IHierarchicalDataSource interface represents has changed.

适用于

另请参阅