DataBoundControl.PerformDataBinding メソッド
アセンブリ: System.Web (system.web.dll 内)


DataBoundControl クラスからデータ バインド コントロールを派生させる場合、DataBind メソッドでなくこのメソッドを実装します。コントロールのデータ バインディング ロジックを PerformDataBinding に配置すると、DataBinding イベントと DataBound イベントが不正な順序で発生することを防止できます。
DataBoundControl 基本クラスには、このメソッドの特定の実装は用意されていませんが、PerformSelect メソッドから PerformDataBinding メソッドを呼び出して、任意のユーザー インターフェイス (UI) コントロールの値を PerformSelect メソッドで取得したデータにバインドできます。

DataBoundControl の派生クラス内で PerformDataBinding メソッドを実装する方法を次のコード例に示します。TextBoxSet コントロールは、バインド先の各データ項目に対し、TextBox コントロールを作成します。このコード例は、DataBoundControl クラスのトピックで取り上げているコード例の一部分です。
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 'PerformDataBinding
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); } } }

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- DataBoundControl.PerformDataBinding メソッドのページへのリンク