DataBoundControl.PerformDataBinding(IEnumerable) 메서드

정의

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

protected public:
 virtual void PerformDataBinding(System::Collections::IEnumerable ^ data);
protected internal virtual void PerformDataBinding (System.Collections.IEnumerable data);
abstract member PerformDataBinding : System.Collections.IEnumerable -> unit
override this.PerformDataBinding : System.Collections.IEnumerable -> unit
Protected Friend Overridable Sub PerformDataBinding (data As IEnumerable)

매개 변수

data
IEnumerable

IEnumerable 메서드 호출에서 반환된 데이터의 PerformSelect() 목록입니다.

예제

다음 코드 예제를 구현 하는 방법에 설명 합니다 PerformDataBinding 에서 파생 된 클래스에서 메서드가 DataBoundControl합니다. 컨트롤은 TextBoxSet 바인딩된 TextBox 각 데이터 항목에 대한 컨트롤을 만듭니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 DataBoundControl 클래스입니다.

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

    // If the data is retrieved from an IDataSource as an 
    // IEnumerable collection, attempt to bind its values to a 
    // set of TextBox controls.
    if (retrievedData != null) {

        foreach (object dataItem in retrievedData) {
            
            TextBox box = new TextBox();
            
            // The dataItem is not just a string, but potentially
            // a System.Data.DataRowView 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) {
                box.Text = DataBinder.GetPropertyValue(dataItem, 
                    DataTextField, null);
            }
            else {
                PropertyDescriptorCollection props = 
                    TypeDescriptor.GetProperties(dataItem);

                // Set the "default" value of the TextBox.
                box.Text = String.Empty;
                
                // Set the true data-bound value of the TextBox,
                // if possible.
                if (props.Count >= 1) {                        
                    if (null != props[0].GetValue(dataItem)) {
                        box.Text = props[0].GetValue(dataItem).ToString();
                    }
                }
            }                                        
            
            BoxSet.Add(box);
        }
    }
}
Protected Overrides Sub PerformDataBinding(ByVal retrievedData As IEnumerable)
    MyBase.PerformDataBinding(retrievedData)

    ' If the data is retrieved from an IDataSource as an IEnumerable 
    ' collection, attempt to bind its values to a set of TextBox controls.
    If Not (retrievedData Is Nothing) Then

        Dim dataItem As Object
        For Each dataItem In retrievedData

            Dim box As New TextBox()

            ' The dataItem is not just a string, but potentially
            ' a System.Data.DataRowView 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
                box.Text = DataBinder.GetPropertyValue( _
                dataItem, DataTextField, Nothing)
            Else
                Dim props As PropertyDescriptorCollection = _
                    TypeDescriptor.GetProperties(dataItem)

                ' Set the "default" value of the TextBox.
                box.Text = String.Empty

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

            BoxSet.Add(box)
        Next dataItem
    End If

End Sub

설명

대신이 메서드를 구현 합니다 DataBind 에서 데이터 바인딩된 컨트롤을 파생 하는 경우 메서드는 DataBoundControl 클래스입니다. 컨트롤의 데이터 바인딩 논리를 에 PerformDataBinding 배치하면 및 DataBound 이벤트가 잘못된 순서로 발생하는 것을 방지 DataBinding 할 수 있습니다.

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

적용 대상