The Table Control and Record Control are user interface controls and have a lifecycle of
their own, just like the lifecycle of each of the controls on a page. It is important to
understand the lifecycle of the table and record control classes since the page delegates
the responsibility of reading the data from the database and retrieving and validating the
data from the user interface prior to saving it in the database.
The query used to read data from the database is a composite query that is formed based on
the static WHERE clause specified by the developer and the dynamic settings specified by the
end user. The static query might be:
SELECT *
FROM Customers
WHERE Customers.State = California
|
When the end user views the information, he or she might search for some information within
the table, further filter by another field, sort by a column and display the third page of
information. In this case, the pseudo-query might look something like:
SELECT rows 31 to 40
FROM Customers
WHERE Customers.State = California AND
Customers.LastName LIKE ‘%Smith%’
ORDER BY Customers.ZipCode DESC
|
During the lifecycle of a table or record control, you have an opportunity to further modify
the query before it is executed by overriding the CreateWhereClause method. You can also review
the data retrieved and make any changes before presentation to the user, or calculate values that
are dependent on the rows retrieved by overriding the DataBind method. Please note that the query
only returns the rows that are being displayed on the web page, not all of the rows that would be returned
by the query. For example, if each page displays 10 records, and page 4 is being currently displayed, the
query will return only records 31 through 40.
Calling Hierarchy of a Page with a Table Control when Displaying Data
The calling hierarchy of a page with a table control when displaying data shows the various
methods that are called at the Page, Table Control and Record Control class levels. When displaying
data, most of the work is performed by handling the Load event at the page class level. The Load event
is handled by Page_Load, LoadData and LoadData_Base methods at the page level. The LoadData_Base method
then calls the LoadData and DataBind methods for each of the Table Control classes on the page. LoadData
then calls CreateWhereClause to create the clause that is used to read the data from the database. The DataBind
binds the data to the user interface controls and also binds the pagination controls. Any dropdown filter lists
are populated by calling the PopulateFilter methods.
Calling Hierarchy of a Page with a Table Control when Filtering, Sorting or Searching Data
The calling hierarchy of a page with a table control when filtering, sorting or searching data
shows the various methods that are called at the Page, Table Control and Record Control class levels.
When filtering, sorting or searching data, most of the work is performed by the PreRender method at the
Table Control class level. The PreRender method takes the settings set earlier by one of the Click or
SelectedIndexChanged events at the Table Control class level. PreRender then checks to see if the data
needs to be reloaded and calls the LoadData and DataBind methods for the Table Control class. LoadData
then calls CreateWhereClause to create the clause that is used to read the data from the database. The
DataBind binds the data to the user interface controls and also binds the pagination controls. Any dropdown
filter lists are re-populated by calling the PopulateFilter methods.
Calling Hierarchy of a Page with a Record Control when Displaying Data
The calling hierarchy of a page with a record control when displaying data shows the various methods
that are called at the Page and Record Control class levels. When displaying data, most of the work
is performed by handling the Load event at the page class level. The Load event is handled by Page_Load,
LoadData and LoadData_Base methods at the page level. The LoadData_Base method then calls the LoadData and
DataBind methods for each of the Record Control classes on the page. LoadData then calls CreateWhereClause to
create the clause that is used to read the data from the database. The DataBind binds the data to the user
interface controls. Any dropdown lists used on the record page is also populated by calling the PopulateFieldDropDownList
method from DataBind.
|