Bagikan melalui


BaseDataBoundControl.RequiresDataBinding Properti

Definisi

Mendapatkan atau menetapkan nilai yang menunjukkan apakah DataBind() metode harus dipanggil.

protected:
 property bool RequiresDataBinding { bool get(); void set(bool value); };
protected bool RequiresDataBinding { get; set; }
member this.RequiresDataBinding : bool with get, set
Protected Property RequiresDataBinding As Boolean

Nilai Properti

Nilai yang dikembalikan adalah true jika metode kontrol DataBind() terikat data harus dipanggil sebelum kontrol dirender; jika tidak, nilainya adalah false.

Contoh

Contoh kode berikut menunjukkan bagaimana RequiresDataBinding properti digunakan oleh kelas kontrol terikat data turunan. Setelah data diambil oleh GetData metode dan terikat ke kontrol dengan PerformDataBinding metode , RequiresDataBinding properti diatur ke false dan MarkAsDataBound metode dipanggil untuk memberi sinyal bahwa kontrol telah selesai mengikat dan tidak lagi memerlukan properti ini selama siklus hidup halaman saat ini. Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk DataBoundControl kelas .

protected override void PerformSelect() {            

   // Call OnDataBinding here if bound to a data source using the
   // DataSource property (instead of a DataSourceID), because the
   // databinding statement is evaluated before the call to GetData.       
    if (!IsBoundUsingDataSourceID) {
        OnDataBinding(EventArgs.Empty);
    }            
    
    // The GetData method retrieves the DataSourceView object from  
    // the IDataSource associated with the data-bound control.            
    GetData().Select(CreateDataSourceSelectArguments(), 
        OnDataSourceViewSelectCallback);
    
    // The PerformDataBinding method has completed.
    RequiresDataBinding = false;
    MarkAsDataBound();
    
    // Raise the DataBound event.
    OnDataBound(EventArgs.Empty);
}
Protected Overrides Sub PerformSelect()

    ' Call OnDataBinding here if bound to a data source using the 
    ' DataSource property (instead of a DataSourceID) because the 
    ' data-binding statement is evaluated before the call to GetData.
    If Not IsBoundUsingDataSourceID Then
        OnDataBinding(EventArgs.Empty)
    End If

    ' The GetData method retrieves the DataSourceView object from the 
    ' IDataSource associated with the data-bound control.            
    GetData().Select(CreateDataSourceSelectArguments(), _
        AddressOf OnDataSourceViewSelectCallback)

    ' The PerformDataBinding method has completed.
    RequiresDataBinding = False
    MarkAsDataBound()

    ' Raise the DataBound event.
        OnDataBound(EventArgs.Empty)

End Sub

Keterangan

Jika Anda mengatur RequiresDataBinding properti ke true ketika kontrol terikat data sudah mulai merender outputnya ke halaman, permintaan HTTP saat ini bukan panggilan balik, dan Anda menggunakan DataSourceID properti untuk mengidentifikasi kontrol sumber data yang akan diikat, DataBind metode dipanggil segera. Dalam hal ini, RequiresDataBinding properti tidak benar-benar diatur ke true.

Berlaku untuk

Lihat juga