Export (0) Print
Expand All
0 out of 3 rated this helpful - Rate this topic

BaseDataBoundControl.OnDataBound Method

Note: This method is new in the .NET Framework version 2.0.

Raises the DataBound event.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

protected virtual void OnDataBound (
	EventArgs e
)
protected void OnDataBound (
	EventArgs e
)
protected function OnDataBound (
	e : EventArgs
)

Parameters

e

An EventArgs object that contains the event data.

This method notifies a server control that any data binding logic associated with the control has completed.

NoteImportant:

The DataBind method is sealed on all controls derived from BaseDataBoundControl. Data-bound controls should override PerformDataBinding instead of the DataBind method to bind data. If DataBind is overridden, the OnDataBinding and OnDataBound events are raised out of order.

Raising an event invokes the event handler through a delegate. For more information, see Raising an Event.

The OnDataBound method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

Notes to Inheritors When overriding OnDataBound in a derived class, be sure to call the base class’s OnDataBound method so that registered delegates receive the event.

The following code example demonstrates how the OnDataBound method is used to raise the DataBound event by a derived data-bound control class. 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. 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);
}

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.