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
PerformSelect() メソッド呼び出しから返されるデータのIEnumerableリスト。
例
次のコード例では、DataBoundControl から派生したクラスにPerformDataBinding メソッドを実装する方法を示します。
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
注釈
DataBoundControl クラスからデータ バインド コントロールを派生させる場合は、DataBind メソッドの代わりにこのメソッドを実装します。 PerformDataBindingにコントロールのデータ バインディング ロジックを配置すると、DataBindingイベントとDataBoundイベントが間違った順序で発生することを回避できます。
基本DataBoundControl クラスは、このメソッドの特定の実装を提供しませんが、PerformDataBinding メソッドは、ユーザー インターフェイス (UI) コントロールの値を、PerformSelect メソッドによって取得されたデータにバインドするために、PerformSelect メソッドによって呼び出されます。