BaseDataBoundControl.OnDataBound(EventArgs) Método
Definição
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)
Parâmetros
Exemplos
O exemplo de código a seguir demonstra como o OnDataBound método é usado para gerar o DataBound evento por uma classe de controle de ligação de dados derivada.The following code example demonstrates how the OnDataBound method is used to raise the DataBound event by a derived data-bound control class. Depois de usar GetData os PerformDataBinding métodos e para associar dados ao controle, o controle de vinculação de dados gera o DataBound evento para sinalizar que a vinculação de dados foi concluída.After using the GetData and PerformDataBinding methods to bind data to the control, the data-bound control raises the DataBound event to signal that data binding is complete. Este exemplo de código faz parte de um exemplo maior fornecido para a DataBoundControl classe.This code example is part of a larger example provided for the DataBoundControl class.
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
Comentários
Esse método notifica um controle de servidor que qualquer lógica de ligação de dados associada ao controle foi concluída.This method notifies a server control that any data binding logic associated with the control has completed.
Importante
O DataBind método é lacrado em todos os controles derivados de BaseDataBoundControl .The DataBind method is sealed on all controls derived from BaseDataBoundControl. Os controles vinculados a dados devem substituir PerformDataBinding em vez do DataBind método para associar dados.Data-bound controls should override PerformDataBinding instead of the DataBind method to bind data. Se DataBind for substituído, os OnDataBinding OnDataBound eventos e serão gerados fora de ordem.If DataBind is overridden, the OnDataBinding and OnDataBound events are raised out of order.
A geração de um evento invoca o manipulador de eventos por meio de um delegado.Raising an event invokes the event handler through a delegate. Para obter mais informações, consulte manipulando e gerando eventos.For more information, see Handling and Raising Events.
O OnDataBound método também permite que classes derivadas manipulem o evento sem anexar um delegado.The OnDataBound method also allows derived classes to handle the event without attaching a delegate. Essa é a técnica preferida para manipular o evento em uma classe derivada.This is the preferred technique for handling the event in a derived class.
Notas aos Herdeiros
Ao substituir OnDataBound(EventArgs) em uma classe derivada, não se esqueça de chamar o método da classe base OnDataBound(EventArgs) para que os delegados registrados recebam o evento.When overriding OnDataBound(EventArgs) in a derived class, be sure to call the base class' OnDataBound(EventArgs) method so that registered delegates receive the event.