BaseDataBoundControl.RequiresDataBinding Właściwość

Definicja

Pobiera lub ustawia wartość wskazującą, czy należy wywołać metodę DataBind() .

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

Wartość właściwości

Zwracana wartość to true , jeśli metoda kontrolki DataBind() powiązanej z danymi powinna zostać wywołana przed renderowaniem kontrolki. W przeciwnym razie wartość to false.

Przykłady

W poniższym przykładzie kodu pokazano, jak RequiresDataBinding właściwość jest używana przez pochodną klasę kontrolki powiązanej z danymi. Po pobraniu danych przez metodę GetData i powiązaniu z kontrolką za PerformDataBinding pomocą metody RequiresDataBinding właściwość jest ustawiona na false , a MarkAsDataBound metoda jest wywoływana w celu sygnalizowania, że kontrolka zakończyła powiązanie i nie wymaga już tej właściwości podczas cyklu życia bieżącej strony. Ten przykład kodu jest częścią większego przykładu udostępnionego DataBoundControl dla klasy .

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

Uwagi

Jeśli właściwość zostanie ustawiona RequiresDataBinding na true , gdy kontrolka powiązana z danymi już zaczęła renderować dane wyjściowe na stronie, bieżące żądanie HTTP nie jest wywołaniem zwrotnym i używasz DataSourceID właściwości w celu zidentyfikowania kontrolki źródła danych do powiązania, DataBind metoda jest wywoływana natychmiast. W tym przypadku RequiresDataBinding właściwość nie jest w rzeczywistości ustawiona na truewartość .

Dotyczy

Zobacz też