HierarchicalDataBoundControl.GetData メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HierarchicalDataBoundControl.GetData メソッドの意味・解説 

HierarchicalDataBoundControl.GetData メソッド

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

データ操作実行するために、データ バインド コントロール使用する HierarchicalDataSourceView オブジェクト取得します

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

Protected Overridable Function
 GetData ( _
    viewPath As String _
) As HierarchicalDataSourceView
Dim viewPath As String
Dim returnValue As HierarchicalDataSourceView

returnValue = Me.GetData(viewPath)
protected virtual HierarchicalDataSourceView GetData (
    string viewPath
)
protected:
virtual HierarchicalDataSourceView^ GetData (
    String^ viewPath
)
protected HierarchicalDataSourceView GetData (
    String viewPath
)
protected function GetData (
    viewPath : String
) : HierarchicalDataSourceView

パラメータ

viewPath

取得するビュー階層パス

戻り値
データ操作実行するためにデータ バインド コントロール使用する HierarchicalDataSourceView オブジェクト

例外例外
例外種類条件

InvalidOperationException

指定されviewPath では、HierarchicalDataSourceView取得できませんでした

解説解説

GetData メソッドは、GetDataSource メソッド呼び出すことで、関連するデータ ソース コントロールから HierarchicalDataSourceView オブジェクト取得します

使用例使用例

GetData メソッド呼び出して関連するデータ ソース コントロールから HierarchicalDataSourceView オブジェクト取得する方法、および HierarchicalDataSourceView.Select メソッド呼び出してデータ取得する方法次のコード例示します。このコード例は、HierarchicalDataBoundControl クラストピック取り上げているコード例一部分です。

Protected Overrides Sub
 PerformDataBinding()
    MyBase.PerformDataBinding()

    ' Do not attempt to bind data if there is no
    ' data source set.
    If Not IsBoundUsingDataSourceID AndAlso
 DataSource Is Nothing Then
        Return
    End If

    Dim view As HierarchicalDataSourceView
 = GetData(RootNode.DataPath)

    If view Is Nothing Then
        Throw New InvalidOperationException
 _
        ("No view returned by data source control.")
    End If

    Dim enumerable As IHierarchicalEnumerable
 = view.Select()
    If Not (enumerable Is
 Nothing) Then

        Nodes.Clear()

        Try
            RecurseDataBindInternal(RootNode, enumerable, 1)
        Finally
        End Try
    End If

End Sub ' PerformDataBinding

Private Sub RecurseDataBindInternal(ByVal
 node As TreeNode, _
    ByVal enumerable As IHierarchicalEnumerable,
 _
    ByVal depth As Integer)

    Dim item As Object
    For Each item In enumerable

        Dim data As IHierarchyData = enumerable.GetHierarchyData(item)

        If Not data Is Nothing
 Then

            ' Create an object that represents the bound data
            ' to the control.
            Dim newNode As New
 TreeNode()
            Dim rvnode As New
 RootViewNode()

            rvnode.Node = newNode
            rvnode.Depth = depth

            ' The dataItem is not just a string, but potentially
            ' an XML node or some other container. 
            ' If DataTextField is set, use it to determine which 
            ' field to render. Otherwise, use the first field.     
               
            If DataTextField.Length > 0 Then
                newNode.Text = DataBinder.GetPropertyValue _
                (data, DataTextField, Nothing)
            Else
                Dim props As PropertyDescriptorCollection
 = _
                TypeDescriptor.GetProperties(data)

                ' Set the "default" value of the node.
                newNode.Text = String.Empty

                ' Set the true data-bound value of the TextBox,
                ' if possible.
                If props.Count >= 1 Then
                    If Not props(0).GetValue(data)
 Is Nothing Then
                        newNode.Text = props(0).GetValue(data).ToString()
                    End If
                End If
            End If

            Nodes.Add(rvnode)

            If data.HasChildren Then
                Dim newEnumerable As IHierarchicalEnumerable
 = _
                    data.GetChildren()
                If Not (newEnumerable Is
 Nothing) Then
                    RecurseDataBindInternal(newNode, _
                    newEnumerable, depth + 1)
                End If
            End If

            If MaxDepth < depth Then
                MaxDepth = depth
            End If
        End If
    Next item

End Sub 'RecurseDataBindInternal

protected override void PerformDataBinding()
 {
    base.PerformDataBinding();

    // Do not attempt to bind data if there is no
    // data source set.
    if (!IsBoundUsingDataSourceID && (DataSource == null))
 {
        return;
    }
    
    HierarchicalDataSourceView view = GetData(RootNode.DataPath);
    
    if (view == null) {
        throw new InvalidOperationException
            ("No view returned by data source control.");
    }                                  
    
    IHierarchicalEnumerable enumerable = view.Select();
    if (enumerable != null) {
                    
        Nodes.Clear();
                        
        try {
            RecurseDataBindInternal(RootNode, enumerable, 1);
        }
        finally {
        
        }
    }
}
private void RecurseDataBindInternal(TreeNode
 node, 
    IHierarchicalEnumerable enumerable, int depth) {         
                           
                
    foreach(object item in enumerable) {
        IHierarchyData data = enumerable.GetHierarchyData(item);

        if (null != data) {
            // Create an object that represents the bound data
            // to the control.
            TreeNode newNode = new TreeNode();
            RootViewNode rvnode = new RootViewNode();
            
            rvnode.Node = newNode;
            rvnode.Depth = depth;

            // The dataItem is not just a string, but potentially
            // an XML node or some other container. 
            // If DataTextField is set, use it to determine which 
            // field to render. Otherwise, use the first field.    
                
            if (DataTextField.Length > 0) {
                newNode.Text = DataBinder.GetPropertyValue
                    (data, DataTextField, null);
            }
            else {
                PropertyDescriptorCollection props = 
                    TypeDescriptor.GetProperties(data);

                // Set the "default" value of the node.
                newNode.Text = String.Empty;                        

                // Set the true data-bound value of the TextBox,
                // if possible.
                if (props.Count >= 1) {                   
     
                    if (null != props[0].GetValue(data))
 {
                        newNode.Text = 
                            props[0].GetValue(data).ToString();
                    } 
                }
            }

            Nodes.Add(rvnode);                    
            
            if (data.HasChildren) {
                IHierarchicalEnumerable newEnumerable = 
                    data.GetChildren();
                if (newEnumerable != null)
 {                            
                    RecurseDataBindInternal(newNode, 
                        newEnumerable, depth+1 );
                }
            }
            
            if ( _maxDepth < depth) _maxDepth = depth;
            
        }
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HierarchicalDataBoundControl クラス
HierarchicalDataBoundControl メンバ
System.Web.UI.WebControls 名前空間
DataBoundControl.DataMember プロパティ
GetDataSource


このページでは「.NET Framework クラス ライブラリ リファレンス」からHierarchicalDataBoundControl.GetData メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からHierarchicalDataBoundControl.GetData メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からHierarchicalDataBoundControl.GetData メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

HierarchicalDataBoundControl.GetData メソッドのお隣キーワード
検索ランキング

   

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



HierarchicalDataBoundControl.GetData メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS