HierarchicalDataBoundControl.PerformDataBinding 메서드

정의

파생 클래스에서 재정의된 경우 데이터 소스의 데이터를 컨트롤에 바인딩합니다.

protected public:
 virtual void PerformDataBinding();
protected internal virtual void PerformDataBinding ();
abstract member PerformDataBinding : unit -> unit
override this.PerformDataBinding : unit -> unit
Protected Friend Overridable Sub PerformDataBinding ()

예제

다음 코드 예제를 구현 하는 방법에 설명 합니다 PerformDataBinding 에서 파생 된 클래스에서 메서드가 HierarchicalDataBoundControl합니다. GeneologyTree 반복으로 제어를 IHierarchicalEnumerableIHierarchyData 해당 연결에서 개체 검색 HierarchicalDataSourceView에 바인딩된 데이터에 대 한 텍스트 트리 구조를 만듭니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 HierarchicalDataBoundControl 클래스입니다.

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;
        }
    }
}
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

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

설명

대신이 메서드를 구현 합니다 DataBind 에서 데이터 바인딩된 컨트롤을 파생 하는 경우 메서드는 HierarchicalDataBoundControl 클래스입니다. 컨트롤의 데이터 바인딩 논리를 배치 PerformDataBinding 유지 합니다 DataBindingDataBound 이벤트가 잘못 된 순서로 발생 합니다.

기본 HierarchicalDataBoundControl 클래스에는이 메서드에 대 한 특정 구현을 제공 합니다 PerformDataBinding 메서드를 호출는 PerformSelect 에서 검색 된 데이터에 사용자 인터페이스 컨트롤의 값을 바인딩하는 메서드는 PerformSelect 메서드.

적용 대상