Personal notes on software development.
For Java technologies check my dedicated site

Pages



  • Using the DataBound Event Handler[1]
When data is bound to a DetailsView, either from a data source control or through programmatically assigning data to the control's DataSource property and calling its DataBind() method, the following sequence of steps occur:
  1. The data Web control's DataBinding event fires.
  2. The data is bound to the data Web control.
  3. The data Web control's DataBound event fires.
Custom logic can be injected immediately after steps 1 and 3 through an event handler. By creating an event handler for the DataBound event we can programmatically determine the data that has been bound to the data Web control and adjust the formatting as needed.

These three simple steps are sufficient for web controls like DetailsView and FormView because they display only a single record. For the GridView, which displays all records bound to it (not just the first), step 2 is a bit more involved:

In step 2 the GridView enumerates the data source and, for each record, creates a GridViewRow instance and binds the current record to it. For each GridViewRow added to the GridView, two events are raised:
  • RowCreated fires after the GridViewRow has been created
  • RowDataBound fires after the current record has been bound to the GridViewRow.
For the GridView, then, data binding is more accurately described by the following sequence of steps:
  1. The GridView's DataBinding event fires.
  2. The data is bound to the GridView.

    For each record in the data source
    1. Create a GridViewRow object
    2. Fire the RowCreated event
    3. Bind the record to the GridViewRow
    4. Fire the RowDataBound event
    5. Add the GridViewRow to the Rows collection
  3. The GridView's DataBound event fires.
To customize the format of the GridView's individual records, then, we need to create an event handler for the RowDataBound event.

  • Paging Server-Side Workflow [2]:
When the end user clicks on a button in the paging interface, a postback ensues and the following server-side workflow begins:
  1. The GridView's (or DetailsView or FormView) PageIndexChanging event fires
  2. The ObjectDataSource re-requests all of the data from the BLL; the GridView s PageIndex and PageSize property values are used to determine what records returned from the BLL need to be displayed in the GridView
  3. The GridView s PageIndexChanged event fires

Related articles:
[1] - Custom Formatting Based Upon Data
[2] - Paging and Sorting Report Data

No comments:

Post a Comment