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. FileSystemDataSource類別會提供方法的執行 GetHierarchicalView ,此方法會為指定的檔案系統路徑抓取強型別 view 物件。The FileSystemDataSource class provides an implementation of the GetHierarchicalView method, which retrieves a strongly typed view object for a specified file system path. 這個程式碼範例是針對類別提供之較大範例的一部分 HierarchicalDataSourceControlThis 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 類別,這是介面的基底 ASP.NET 實作為 IHierarchicalDataSource 介面。Data source controls that represent hierarchical data derive from the HierarchicalDataSourceControl class, which is the base ASP.NET implementation of the IHierarchicalDataSource interface. IHierarchicalDataSource介面是用來定義資料來源控制項,以將階層式資料(而不是表格式或清單樣式的資料)公開至衍生自類別的 Web 服務器控制項 HierarchicalDataBoundControl ,例如 TreeView 控制項。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. 介面會定義單一方法, 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 傳遞給方法的參數 GetHierarchicalViewThe 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 資料來源 view 物件,會執行插入、更新、刪除和排序等作業。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 介面,取得檢視 Helper 物件。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.

適用於

另請參閱