HierarchicalDataSourceViewとは? わかりやすく解説

HierarchicalDataSourceView クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

ノードまたはノードのコレクションのデータ ビューを、HierarchicalDataSourceControl コントロールの階層データ構造で表します。

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public MustInherit Class
 HierarchicalDataSourceView
Dim instance As HierarchicalDataSourceView
public abstract class HierarchicalDataSourceView
public ref class HierarchicalDataSourceView
 abstract
public abstract class HierarchicalDataSourceView
public abstract class HierarchicalDataSourceView
解説解説

ASP.NET では、Web サーバー コントロールをデータにバインドして、一貫した方式で提供できるようにするデータ バインディング アーキテクチャがサポートされています。データにバインドされる Web サーバー コントロールをデータ バインド コントロールといいます。また、そのバインディングを容易にするクラスをデータ ソース コントロールといいます。データ ソース コントロールは、ファイル、ストリーム、リレーショナル データベース、ビジネス オブジェクトなど、あらゆるデータ ソースを表すことができます。データ ソース コントロールにより、基になるデータのソースや形式にかかわらず、一貫した方式でデータがデータ バインド コントロールに提供されます。

階層データを表すデータ ソース コントロールは、HierarchicalDataSourceControl 抽象クラスから派生しています。データ ソース コントロールは、データ ソース コントロール オブジェクトと、それに関連付けられた、基になるデータのビューを組み合わせたものと考えることができます。ビューは、データ ソース ビュー オブジェクトによって表されます。階層構造のデータ ソース コントロールでは、それらのコントロールによって表されるデータの各階層レベルに対して、階層構造のデータ ソース ビューがサポートされます。データ ソース ビューは、DataSourceControl コントロールに関連付けられている DataSourceView オブジェクトのような名前が付けられていませんが、一意の階層パスによって識別できます。

データ ソース ビューでは、データ ソース コントロールの機能が定義されます。HierarchicalDataSourceView を含むすべてのデータ ソース ビュー オブジェクトでは、基になるデータ ソースからのデータの取得がサポートされます。データの取得は、データの階層リストを IHierarchicalEnumerable オブジェクトとして取得する Select メソッドを使用して行われます。すべてのデータ ソース ビュー オブジェクトには、Insert、Update、Delete、並べ替えなどの操作を含む、一連の基本的な機能がオプションとして用意されています。データ バインド コントロールにより、データ ソース コントロールの機能を検出できます。この操作は、データ ソース コントロールに関連付けられたデータ ソース ビューを GetHierarchicalView メソッドを使用して取得し、デザイン時または実行時にそのビューにクエリすることによって実行できます。HierarchicalDataSourceView では、現在 Insert、Update または Delete の操作がサポートされていません。

継承時の注意 HierarchicalDataSourceView から継承する場合は、Select のメンバをオーバーライドする必要があります。

使用例使用例

次のコード例では、HierarchicalDataSourceView クラスからクラスを派生して、階層構造のデータ ストレージ (この場合はファイル システム) からデータを取得する方法を示します。FileSystemDataSourceView クラスは、厳密に型指定された HierarchicalDataSourceView インスタンスです。このインスタンスを使用すると、TreeView コントロールなどの階層構造の Web サーバー コントロールを FileSystemDataSource コントロールにバインドしてファイル システム情報を表示できるようになります。セキュリティ上の理由で、ファイル システム情報が表示されるのは、データ ソース コントロールが、ローカルホスト上で認証された状態で使用されており、そのデータ ソース コントロールを使用する Web フォーム ページが存在する仮想ディレクトリでのみ起動する場合に限られます。それ以外の場合は、コンストラクタに渡された viewPath パラメータが使用され、現在のファイル システム パスに基づいてビューが作成されます。このコード例は、HierarchicalDataSourceControl クラスのトピックで取り上げているコード例の一部分です。

' The FileSystemDataSourceView class encapsulates the
' capabilities of the FileSystemDataSource data source control.

Public Class FileSystemDataSourceView
   Inherits HierarchicalDataSourceView

   Private _viewPath As String

   Public Sub New(viewPath
 As String)
       ' This implementation of HierarchicalDataSourceView does not
       ' use the viewPath parameter but other implementations
       ' could make use of it for retrieving values.
       _viewPath = viewPath
   End Sub 'New


   ' Starting with the rootNode, recursively build a list of
   ' FileSystemInfo nodes, create FileSystemHierarchyData
   ' objects, add them all to the FileSystemHierarchicalEnumerable,
   ' and return the list.
   Public Overrides Function
 [Select]() As IHierarchicalEnumerable
      Dim currentRequest As HttpRequest = HttpContext.Current.Request

      ' SECURITY: There are many security issues that can be raised
      ' SECURITY: by exposing the file system structure of a Web server
      ' SECURITY: to an anonymous user in a limited trust scenario such
 as
      ' SECURITY: a Web page served on an intranet or the Internet.
      ' SECURITY: For this reason, the FileSystemDataSource only
      ' SECURITY: shows data when the HttpRequest is received
      ' SECURITY: from a local Web server. In addition, the data source
      ' SECURITY: does not display data to anonymous users.
      If currentRequest.IsAuthenticated AndAlso(currentRequest.UserHostAddress
 = "127.0.0.1" OrElse currentRequest.UserHostAddress
 = "::1") Then

         ' The ApplicationPath returns a physical path in VB, so do
 not MapPath.
         Dim rootPath As String
 = currentRequest.MapPath(currentRequest.ApplicationPath)

         Dim rootDirectory As New
 DirectoryInfo(rootPath)

         Dim fshe As New
 FileSystemHierarchicalEnumerable()

         Dim fsi As FileSystemInfo
         For Each fsi In
  rootDirectory.GetFileSystemInfos()
            fshe.Add(New FileSystemHierarchyData(fsi))
         Next fsi
         Return fshe
      Else
         Throw New NotSupportedException("The
 FileSystemDataSource only " + "presents data in
 an authenticated, localhost context.")
      End If
   End Function 'Select
End Class 'FileSystemDataSourceView
// The FileSystemDataSourceView class encapsulates the
// capabilities of the FileSystemDataSource data source control.
public class FileSystemDataSourceView : HierarchicalDataSourceView
{
private string _viewPath;

    public FileSystemDataSourceView(string
 viewPath)
    {
        // This implementation of HierarchicalDataSourceView does not
        // use the viewPath parameter but other implementations
        // could make use of it for retrieving values.
        _viewPath = viewPath;
    }

    // Starting with the rootNode, recursively build a list of
    // FileSystemInfo nodes, create FileSystemHierarchyData
    // objects, add them all to the FileSystemHierarchicalEnumerable
,
    // and return the list.
    public override IHierarchicalEnumerable Select() {
        HttpRequest currentRequest = HttpContext.Current.Request;

        // SECURITY: There are many security issues that can be raised
        // SECURITY: by exposing the file system structure of a Web
 server
        // SECURITY: to an anonymous user in a limited trust scenario
 such as
        // SECURITY: a Web page served on an intranet or the Internet.
        // SECURITY: For this reason, the FileSystemDataSource only
        // SECURITY: shows data when the HttpRequest is received
        // SECURITY: from a local Web server. In addition, the data
 source
        // SECURITY: does not display data to anonymous users.
        if ( currentRequest.IsAuthenticated &&
            (currentRequest.UserHostAddress == "127.0.0.1" ||
             currentRequest.UserHostAddress == "::1"))
        {
            string rootPath = currentRequest.MapPath (currentRequest.ApplicationPath);

            DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);

            FileSystemHierarchicalEnumerable fshe = new FileSystemHierarchicalEnumerable();

            foreach (FileSystemInfo fsi in
 rootDirectory.GetFileSystemInfos()) {
                fshe.Add(new FileSystemHierarchyData(fsi));
            }
            return fshe;
        }
        else {
            throw new NotSupportedException("The FileSystemDataSource
 only " + "presents data in an authenticated, localhost
 context.");
        }
    }
}
.NET Framework のセキュリティ.NET Framework のセキュリティ
継承階層継承階層
System.Object
  System.Web.UI.HierarchicalDataSourceView
     System.Web.UI.WebControls.SiteMapHierarchicalDataSourceView
     System.Web.UI.WebControls.XmlHierarchicalDataSourceView
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HierarchicalDataSourceView メンバ
System.Web.UI 名前空間
DataSourceView クラス
HierarchicalDataSourceControl クラス

HierarchicalDataSourceView コンストラクタ


HierarchicalDataSourceView メソッド


HierarchicalDataSourceView メンバ

ノードまたはノードのコレクションのデータ ビューを、HierarchicalDataSourceControl コントロールの階層データ構造で表します。

HierarchicalDataSourceView データ型で公開されるメンバを以下の表に示します。


プロテクト コンストラクタプロテクト コンストラクタ
  名前 説明
プロテクト メソッド HierarchicalDataSourceView HierarchicalDataSourceView クラスの新しいインスタンスを初期化します。
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

HierarchicalDataSourceView クラス
System.Web.UI 名前空間
DataSourceView クラス
HierarchicalDataSourceControl クラス



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「HierarchicalDataSourceView」の関連用語

HierarchicalDataSourceViewのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HierarchicalDataSourceViewのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS