BaseDataBoundControl.OnDataBound(EventArgs) Metoda

Definicja

DataBound Zgłasza zdarzenie.

protected:
 virtual void OnDataBound(EventArgs ^ e);
protected virtual void OnDataBound (EventArgs e);
abstract member OnDataBound : EventArgs -> unit
override this.OnDataBound : EventArgs -> unit
Protected Overridable Sub OnDataBound (e As EventArgs)

Parametry

e
EventArgs

EventArgs Obiekt, który zawiera dane zdarzenia.

Przykłady

W poniższym przykładzie kodu pokazano, jak OnDataBound metoda jest używana do zgłaszania DataBound zdarzenia przez pochodną klasę kontrolki powiązanej z danymi. Po użyciu GetData metod i PerformDataBinding do powiązania danych z kontrolką kontrolka, kontrolka powiązana z danymi zgłasza DataBound zdarzenie, aby zasygnalizować, że powiązanie danych zostanie zakończone. 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

Ta metoda powiadamia kontrolkę serwera o ukończeniu dowolnej logiki powiązania danych skojarzonej z kontrolką.

Ważne

Metoda DataBind jest zapieczętowana na wszystkich kontrolkach pochodzących z BaseDataBoundControlklasy . Kontrolki powiązane z danymi powinny przesłonić PerformDataBinding zamiast DataBind metody powiązania danych. Jeśli DataBind jest zastępowana, OnDataBinding zdarzenia i OnDataBound są wywoływane poza kolejnością.

Podnoszenie zdarzenia wywołuje program obsługi zdarzeń przez delegata. Aby uzyskać więcej informacji, zobacz Obsługa i podnoszenie zdarzeń.

Metoda OnDataBound umożliwia również klasom pochodnym obsługę zdarzenia bez dołączania delegata. Jest to preferowana technika obsługi zdarzenia w klasie pochodnej.

Uwagi dotyczące dziedziczenia

Podczas zastępowania OnDataBound(EventArgs) w klasie pochodnej należy wywołać metodę klasy OnDataBound(EventArgs) bazowej, aby zarejestrowani delegaci odbierali zdarzenie.

Dotyczy

Zobacz też