DataBoundControl.PerformDataBinding(IEnumerable) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
파생 클래스에서 재정의되는 경우 데이터 원본의 데이터를 컨트롤에 바인딩합니다.
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 검색 되는 PerformSelect 데이터에 모든 사용자 인터페이스 (UI) 컨트롤의 값을 바인딩하기 위해 호출 됩니다.