Applicable to: Microsoft® ASP.NET Summary: Solution to any ASP.NET control to add paging features. It also provides a lot of useful tips and techniques for developing composite ASP.NET controls.
Download the source code of this article
(English). (Please note that in the sample file, the programmer's annotation is used in English. In this article, it is translated into Chinese to facilitate the reader's understanding.) From the programmer's perspective, Microsoft SQL Server? One of the biggest defects of the query It is the number of rows returned usually more than the number of rows that can be accommodated more than the user interface of the application. This kind of embarrassment often traps the developer in a dilemma. Developers should create a very long page that allows users to spend time to scroll browsing, or should you better solve this problem by setting up a manual paging mechanism? Which solution is better, to a large extent, depending on the characteristics of the data to be retrieved. A longer list consisting of multiple items (such as search results), it is best to pass the size of each page, equal to a relatively short multiple page of each page. A longer list consisting of a single item (such as the article), if the entire insert is in a page, it is more convenient to use. The final analysis result is that the decision should be made according to the overall use of the application. So how do Microsoft ASP.NET solves the data paging problem? ASP.NET provides powerful data binding controls to format the query results to HTML tags. However, only one control (ie, DataGrid control) is originally supported in these data binding controls. Other controls (such as DataList, Repeater or CheckBoxList) do not support paging. These controls and other list controls do not support paging, not because they do not support paging in the structure, but because they differ from DataGrid, no specific code for processing paging is not included. However, the code for processing paging is quite sampleized, and can be added to all of these controls. SCOTT MITCHELL introduces DataGrid pagination in the article "CREATING A pageable, Sortable DataGrid". This article also references other useful information on the Web to provide you with the basics and other information about grid paging. You can view this article if you want to see how to make the DataList control. This article demonstrates how to create a custom DataList control with the current index and page size attribute, and you can start the page change event. The same code can also be used to meet the pagination needs of other list controls such as Listbox and CheckBoxList. However, adding paging functions to each control is actually a very good practice, because, as mentioned above, the paging code is quite sampled. Therefore, for smart programmers, what is the way to implement all of these controls for all these controls better than using a new general paging program control? A paging program control will be established in this article, which will enable the partner list control to paginate the query results of SQL Server. This control is called SQLPAGER, which supports two types of partner controls - list controls and underlying data list controls. Significant Features of the SQLPAger control SQLPAger control is an ASP.NET composite control that contains a single line table. The line includes two cells-navigation bars and page descriptors. The user interface of the control is strip, ideally, the width is the same as the width of the partner control. The navigation section provides a clickable element to move between the page; the page descriptor section provides users with some feedback information about the currently displayed page.
Figure 1: SQLPAGER controls displayed in the Visual Studio .Net web designer are the same as the embedded paging program of the DataGrid control, and the SQLPAger control has two navigation modes, which will be next page / previous page and a digital page. In addition, its special attributes Pagerstyle enables you to choose more convenient styles. This control works with the list control. You can specify a such partner control with the ControlTopaginate string property to the paging program. SQLPAGER1.CONTROLTOPAGINATE = "ListBox1";
In general, the paging program first gets the query result of SQL Server, prepares an appropriate record page, and then displays the page through the partner control DataSource property. When the user clicks to view the new page, the paging program retrieves the requested data and displays the data again through the partner control. The paging mechanism is completely transparent to the list control. The data source of the list control is updated by programming, and only the records suitable for the current page are included.
The paging engine of the control has multiple public properties, such as CurrentPageIndex, ItemsPr, and PageCount, through these properties to get the index of the current page, the size of each page, and the total number of pages to display. Paging programs Manage data retrieval and any logic required for paging.
SelectCommand Property Set the command text used by the data. The Connectionstring property defines the name and location of the database and the connection credentials. The way to perform the query depends on the value of the PagingMode property. The possible value of this property is the value of the PagingMode enumeration with its same name - Cached and Noncached. If you select the Cached option, you will search the entire result set using the data adapter and the DataTable object. You can choose to place the result set in the Cache object of the ASP.NET, which can be reused until expired. If you select the Noncached option, the query only retrieves the record that is suitable for the current page. At this time, no data is placed in the cache of ASP.NET. The Noncached mode is almost the same as the custom paging mode of the DataGrid control.
The following table lists all programming interfaces of the SQLPAger control.
Table 1: Programming interface for SQLPAger controls
[html]
"1
"Cellpadding =
"2
"Cellspacing =
"0
"Class = data bordercolordark =
#Fffffffff
">
"#Cccccc
">
"26%
"Align = Left class = data> name tH>
13%
"Align = Left class = data> type th>
"61%
"Align = Left class = data> Description TH>
TR>
"26%
"> Cachedure b> td>
13%
"> Property TD>
"61%
"> Indicates the number of seconds whose data is reserved in the ASP.NET cache. Used only for Cached b> mode. The default is
60 seconds. Td>
TR>
"26%
"> Connectionstring b> td>
13%
"> Properties td>
"61%
"> Use to access the connection string of the selected SQL Server database. Td>
TR>
"26%
"> controltopaginate b> td>
13%
"> Properties td>
"61%
"> The control ID in the same .aspx page, which will display the recording page retrieved by the paging program. This is the partner control. Td>
TR>
"26%
"> CurrentPageIndex b> td>
13%
"> Properties td>
"61%
"> Get and set 0-based page index. Td>
TR>
"26%
"> itemsperpage b> td>
13%
"> Properties td>
"61%
"> Get and set the number of records to display each page. The default value is displayed 10 items per page. Td>
TR>
"26%
"> Pagerstyle b> td>
13%
"> Properties td>
"61%
"This value indicates the style of the page program user interface. It can be enumerated for the PagersTyle: nextprev b> and numericpages b>. In NextPREV B> mode In the middle, the VCR button will be displayed to the first page, the next page, the next page and the last page. In the numericPages b> mode, a drop-down list is displayed, listing all Available page index. Td>
TR>
"26%
"> paningmode b> td>
13%
"> Properties td>
"61%
"This value indicates how to retrieve data. It can be one of PagingMode enumeration values: Cached b> and Noncached b>. If cached b>, The data adapter will be used, and the entire result set will be placed temporarily
ASP.NET cache. If you use Noncached b>, you only retrieve records in the current page. In this case, the cache is not performed. Td>
TR>
"26%
"> SelectCommand b> td>
13%
"> Properties td>
"61%
"> Command text used to check in query. It is best to select-from-where. Do not support
ORDER BY clause. Sort is additionally specified by sortfield b> attribute. Td>
TR>
"26%
"> sortfield b> td>
13%
"> Properties td>
"61%
"> The name of the field used to sort. This field is used to provide dynamic ORDER BY clauses for the query. Sort is made by
SQL Server is executed. Td>
TR>
"26%
"> Clearcache b> td>
13%
"> Method td>
"61%
"> Remove any data stored in the ASP.NET cache. Td> tr>
"26%
"> PageIndexchanged b> td>
13%
"> Events td>
"61%
"> The default event occurs when the paging program moves to another page. The data structure of the event is pagechangeDeventargs b> class, contains the index of the old page and the new page. Td>
TR>
Tbody>
TABLE>
[/ html]
Since the SQLPAger control inherits WebControl, it also has a lot of properties related to the UI to manage fonts, borders, and colors.
Generate SQLPAGER controls
The SQLPAGER control will be generated as a composite control and allow it to inherit the WebControl class. The composite control is unique to the ASP.NET server control, which consists of one or more server controls.
Public Class Sqlpager: WebControl, InamingContainer
{...}
Most of the time is actually generating composite controls unless a fully customized control or existing control is generated. To create SQLPAGER, combine a Table control, and combine several linkbutton controls or a DROPDOWNLIST control based on the style of paging programs.
When you generate a composite control, you need to pay attention to several principles. First, you need to override the CreateChildControls protected method. The CreateChildControls method is inherited from Control. This method will be called when the server control is to display or after returning or after returns.
Protected Override Void CreateChildControls () {// Clear existing child control and its viewState controls.clear (); ClearChildViewState (); // Generate control tree buildcontrolhierarchy ()
When you override this method, you need to perform several important operations. Create and initialize any required sub-control instances and add them to the Controls collection of the parent control. However, before generating a new control tree, you should delete any existing sub-controls and clear any ViewState information that the child control may be left.
Composite components also need to implement InamingContainer interfaces so that ASP.NET can be created for it to create a new naming range. This ensures that all controls in the composite control have a unique name. This will also ensure that the return data of the sub-control can be automatically processed.
It is important to become a naming container for the SQLPAger control. In fact, SQLPager contains some linkbutton controls and needs to get and process them to click on the event to navigate the page. As with any other controls in the ASP.NET page, LinkButton is also given an ID that identifies the control of the process returns.
When processing returns an event, there is a match relationship between the target ID of the event to find the target ID of the event and the main form of the host. LinkButton is a sub-control of the paging program, so the code of its server side cannot be run. Does this mean that only the form's direct child control can start and handle server events? Of course, as long as you use a named container. Change the actual ID of the Embedded Link button to "SQLPAGER1: First" by changing the SQLPAger control implementation in the InamingContainer interface. When the user clicks to view the new page, the return event will be SQLPAGER1: FIRST as the target control. In fact, the algorithm used to identify the target control is more complex than the above. When running, the name of the event destination control is as a string separated by a colon. In fact, this match is done between the sub-control of the form and the first tag that is separated by a colon (such as SQLPAGER1: FIRST). Since the paging program is a sub-control of the form, it will be successful when matching, and the page program acquires a clicked event. If you think this explanation is not enough or puzzled, just download the source code for the SQLPAger control, delete the InamingContainer tag interface and re-compiling. You will see the paging program to return, but cannot process the incident internally.
The InamingContainer interface is a tag interface that does not have a method, which acts simply specify the name in the class declaration without any other operation.
Another important aspect of the composite control is that they usually do not need to be customized. The display of the composite control follows the display of its constituent control. When generating a composite control, there is usually no need to overwrite the Render method.
The SQLPAGER tree of the control consists of a single-line table containing two cells. This table inherits most of the visual settings of the paging program, such as foreground color and background color, border, font information, and width. The first cell contains a navigation bar whose structure depends on the value of the PagerStyle property. If the style of the page program is nextprev, the navigation strip consists of four VCR's buttons. Otherwise, it will consist of a drop-down list.
Private void buildcontrolhirarchy () {// Generate a environment table (one line, two cells) Table t = new table (); t.font.name = this.font.name; t.size = this.font.size T. Borderstyle = this.borderstyle; T. Borderwidth = this.borderwidth; T.BorderColor = this.bordercolor; t.width = this.width; t.height = this.Height; t.backcolor = this.backcolor; t.backcolor = this.backcolor; t.backcolor = this.backcolor; t.backcolor = this.backcolor; t.back .Forecolor = this.forecolor; // Generate a row in the table TableRow Row = New TableRow (); T.ROWS.ADD (ROW); // Generate a cell Tablecell Cellnavbar = new TableCell (); if (PagerStyle == this.PagerStyle.NextPrev) BuildNextPrevUI (cellNavBar); else BuildNumericPagesUI (cellNavBar); row.Cells.Add (cellNavBar); // generating cell TableCell cellPageDesc = new TableCell with a page index (); cellPageDesc. Horizontalalign = horizontalalign.right; buildCurrentPage (CellPageDesc); row.cells.add (CellPageDesc); // Add a table to the control tree this.controls.add (t);} Add each control to the correct controls collection for paging programs The correct display is extremely important. The outermost table must be added to the Controls collection of the paging program. The link button and drop-down list must be added to the Controls collection of the corresponding table cell.
The code used to generate a link button navigation bar will be given below. Each button is displayed with a webdings character, which can be disabled as needed and bound to the internal Click event handler.
private void BuildNumericPagesUI (TableCell cell) {// display a drop-down list DropDownList pageList = new DropDownList (); pageList.ID = "PageList"; pageList.AutoPostBack = true; pageList.SelectedIndexChanged = new EventHandler (PageList_Click); pageList.Font .Name = this.font.name; Pagelist.font.size = font.size; Pagelist.ForeColor = Forecolor; if (Totalpages <= 0 || CurrentPageIndex == -1) {PageList.Items.Add ("NO PAGES" ); Pagelist.enabled = false; pagelist.selectedIndIndex = 0;} else // Plip list {for (int i = 1; i <= Totalpages; i ) {ListItem item = new ListItem (i.tostring (), (i -1) .tostring ()); Pagelist.items.Add (item);} Pagelist.selectedIndex = CurrentPageIndex;}}
All event handlers (Click and SelectedIndexchange "will eventually change the currently displayed pages. Both methods call a common private Private method.
private void first_Click (object sender, EventArgs e) {GoToPage (0);} private void PageList_Click (object sender, EventArgs e) {DropDownList pageList = (DropDownList) sender; int pageIndex = Convert.ToInt32 (pageList.SelectedItem.value); GoToPage (pageIndex);} private void GoToPage (int pageIndex) {// event data ready PageChangedEventArgs e = new PageChangedEventArgs (); e.OldPageIndex = CurrentPageIndex; e.NewPageIndex = pageIndex; // update the current index CurrentPageIndex = pageIndex; / / Start the page Change Event OnPageIndexChanged (E); // Binding the new data DATABIND ();} The difference between the other navigation buttons with first_click is only different from the page number of the Gotopage method. The Gotopage method is responsible for handling the pageIndexchanged event and responsible for starting the data binding process. It prepares event data (old pages and new page indexes) and triggers events. Gotopage is defined as Private, but you can change the displayed page by programming using the CurrentPageIndex property.
[quote]
Public Int CurrentPageIndex
{
Get {return convert.Toint32 (ViewState "
CurrentPageIndex
"]);
Set {ViewState [
CurrentPageIndex
"] =
Value;
}
[/ quote]
Like all properties listed in Table 1, the implementation method of the currentPageIndex property is also quite simple. It saves its content to ViewState and restores it. During the data binding process, the page index will be verified.
Data binding process
The DATABIND method is all ASP.NET controls, for the data binding control, it will trigger the refresh of the user interface to reflect new data. The SQLPAGER control uses this method to start the data search operation using this method according to the value of the selectcommand and the connectionstring property. It goes without saying that if any of these properties is empty, the process will terminate. Similarly, if the partner control does not exist, the data binding process will be canceled. To find partner controls, Database uses the FindControl function in the Page class. It can be seen that the partner control must be a direct sub-control of the main form.
Controls that make paging display cannot be arbitrary ASP.NET server controls. It must be a list control or basic data list control. More generally, the partner control must have a DataSource property and implement the DataBind method. Controls that may be paging actually only need to meet these requirements. All inherited ListControl or baseDataList's controls in Microsoft? .NET Framework meet the first requirements; all web controls meet Database requirements through the design. Using the current implementation method, you cannot use the SQLPAGER control to page the Repeater. The REPEATER is different from the partner control DataList and DataGrid, and does not inherit the BaseDataList, nor does it provide the function of the list control. The following table lists the controls that can be paid using SQLPAGER. Table 2: Data Binding Controls that can be paid by SQLPAger controls
[html]
"1
"Cellpadding =
"2
"Cellspacing =
"0
"Class = data bordercolordark =
#Fffffffff
">
"#Cccccc
">
"twenty two%
"Align = Left Class = Data> Controls TH>
78%
"Align = Left class = data> Description TH>
TR>
"twenty two%
"> CheckBoxList b> td>
78%
"> Distribute from listcontrol b>, display as checkbox list. Td>
TR>
"twenty two%
"> DropDownList b> td>
78%
"> Distribute from ListControl b>, display as a string drop-down list. Td>
TR>
"twenty two%
"> Listbox b> td>
78%
"> Distribute from ListControl b>, display as a string can scroll through the list. Td>
TR>
"twenty two%
"> RadiobuttonList b> td>
78%
"> Distribute from ListControl b>, display as a radio button list. Td>
TR>
"twenty two%
"> Datalist b> td>
78%
"> Distribute from baseDataList b>, display as a list of templated data items. Td>
TR>
"twenty two%
"> DataGrid b> td>
78%
"> From BaseDataList B>, it is displayed as a table grid of a data project. dataGrid b> is the only built-in powerful paging engine
ASP.NET control. Td>
TR>
Tbody>
TABLE>
[/ html]
The following code illustrates the data binding process implemented by the SQLPAger control.
Public override void database.databinding (); // must recreate control ChildControlScreated = false after data binding (); // Make sure the control exists and list control _ControlTopaginate = Page.FindControl controlToPaginate); if (_controlToPaginate == null) return; if ((_ controlToPaginate is BaseDataList || _controlToPaginate is ListControl!)) return; // ensure adequate connection information and specify the query if (ConnectionString == "" || SelectCommand = = "") Return; // Get data IF (PagingMode == PagingMode.cached) fetchaLData (); else fetchPageData (); // Bind data to partner control basedataDataList baseDataListControl = null; ListControl ListControl = NULL; if (IF _controlToPaginate is BaseDataList) {baseDataListControl = (BaseDataList) _controlToPaginate; baseDataListControl.DataSource = _dataSource; baseDataListControl.DataBind (); return;} if (_controlToPaginate is ListControl) {listControl = (ListControl) _controlToPaginate; listControl.Items.Clear (); listControl .Datasource = _datasource; listControl.database (); return;}} Different acquisition routines are called according to the value of the PagingMode property. In any case, the result set binds to the instance of the PagedDataSource class. This class provides some features used to page data. In particular, when the entire data set is stored in the cache, the class will automatically retrieve the record of the current page and return to the Boolean value to provide information about the first page and the last page. The internal structure of this class will be described later. In the above list, the PageDataSource object of the help program is represented by the _DataSource variable.
The SQLPAger control then calculates the type of the partner control and binds the contents of the PageDataSource object to the DataSource property of the partner control.
Sometimes the above DATABIND method also re-sets the ChildControlScreated property to false. So why do you do this?
When the page containing the paging program is returned, all controls are recreated; paging programs are no exception. Normally, all controls and their sub-controls are created before preparing to display the page. At a moment before receiving an onprender notification, the protected ensurechildControls method will be called so that each control can generate its own control tree. After this event, the data binding process is complete, and the new data is stored in the cache.
However, when the page returns due to a constituent control of the paging program (ie, the user clicks to change the page), the control tree of the sub-page program will be generated, and the display phase is not reached. In particular, when processing related server-end events, the control tree must be generated, so that the control tree is generated before the data binding begins. Difficulties are that the data binding will modify the page index, which must be reflected in the user interface. If you do not take some countermeasures, when the user switches to another page, the page index in the paging program will not be refreshed. There are various ways to solve this problem, but it is important to figure out the problem and its real reasons. You can avoid generating control trees and generate all outputs in the Render method. Alternatively, you can also modify the part of the affected data binding changes in the tree. This article selects a third method, which requires less code, and it is possible to solve the problem regardless of which portion of the user interface is subject to data binding changes. You can invalidate the trees of previously created controls by setting the ChildControlScreated property to False. This will recreate the control tree before display.
Pagination engine
The SQLPAger control supports two ways to retrieve data - cache and non-cache. If the former is used, select commands to execute, and the entire result set will be bound to the data source object that is paid inside. The PageDDataSource object will automatically return a record that is suitable for a specific page. The PagedDataSource class is also a system component that is running behind the DataGrid default paging mechanism.
Retrieve all records but only a few records suitable for the page, which is usually not a wise approach. Due to the stateless characteristics of the web application, in fact, a large number of queries may be run each time the page is requested. To make the operation valid, adopting a cache data retrieval method must rely on a cache object, ASP.NET's Cache object is a good candidate object. The use of cache technology speeds up the running speed of the application, but the data snapshot provided cannot reflect the latest changes. In addition, it needs to use more memory on the web server. And ridiculous is that if a large amount of data is cached by a session, it may even cause a big problem. The Cache container is globally for the application; if the data is stored in it, you need to generate a specific item name with a session.
The top of the Cache object is fully supported expiration strategy. In other words, the data stored in the cache can be automatically released after a period of time. The following code illustrates a private method used to get the data and store it in the cache in the SQLPAger class.
[quote]
Private void fetchaalldata ()
{
// Find data in ASP.NET Cache
DataTable data;
Data = (DATATABLE) Page.cache [cachekeyname];
IF (data == null)
{
// Modify SELECTCOMMAND using Order-by information
AdjustSelectCommand (TRUE);
// Go to the database if the data expires or never been acquired
SqlDataAdapter Adapter = New SqldataAdapter (SELECTCOMMAND, CONNECTION);
Data = new datatable ();
Adapter.Fill (data);
Page.cache.insert (CacheKeyname, Data, NULL,
DateTime.now.addseconds (Cacheduration),
System.Web.caching.cache.noslidingExpiration;
}
// Configuring the data source components of the paging
IF (_datasource == null) _DataSource = new pagedDataSource ();
_DataSource.DataSource = data.defaultview;
_DataSource.Allowpaging = true;
_DataSource.pageSize = itemsperpage;
Totalpages = _datasource.pagecount;
/ / Make sure the page index is valid
ValidatePageIndex ();
IF (currentpageIndex == -1)
{
_DataSource = null;
Return;
}
// Select the page you want to view
_DataSource.currentPageIndex = CURRENTPAGEINDEX;
}
[/ quote]
The control and request cache project name are unique. It includes a page of the URL and the ID of the control. Data is bind to the cache within the specified time (in seconds). To expire, you must use the cache.insert method. The following simpler code adds the item to the cache, but does not include any expiration strategy.
[quote]
Page.cache [cachekeyname] = DATA;
[/ quote]
PagedDataSource object Gets data to be paid through its DataSource property. It is worth noting that the DataSource attribute of the PagedDataSource class accepts only the IEnumerable object. DataTable does not satisfy this request, this is why the defaultview property is taken.
The SelectCommand property determines the query running on the SQL Server database. This string is preferably in the form of select-from-where. The ORDER BY clause is not supported, and if the clause is specified, it will be deleted. This is what the AdjustSelectCommand method is. Use the sortfield property to specify any sorting information. The AdjustSelectCommand method itself will add a correct ORDER BY clause according to the value of sortfield. Does this do this?
When the paging program operates in a noncached mode, the original query will be modified to ensure that the current page record is retrieved. The actual query text performed on SQL Server will take the following form.
Select * from (select top itemsperpage * from (select Top Itemsperpage * CurrentpageIndex * from (selectcommand) AS T0 Order by Sortfield ASC) AS T1ORDER BY SORTFIELD DESC) AS T2 ORDER BY SORTFIELD
The query makes up for the defect of the ROWNUM clause in SQL Server 2000, and reorders the record so that only the "Nth" block of the x item is returned after proper sorting. You can specify a base query, and the paging program will be broken down into multiple smaller pages. Only records suitable for a page are returned. As you can see, in addition to the query command, the above query needs to process the sort field. That's why add the sortfield property added. The only drawback of this code is that the default is sorted in ascending. This code is really perfect by allowing ASC / DESC keywords.
Private void fetchPageData () {// Need a validated page index to get data. // The actual page number is also required to verify the page index. AdjustSelectCommand (false); VirtualRecordCount countInfo = CalculateVirtualRecordCount (); TotalPages = countInfo.PageCount; // verification page (or to ensure effective CurrentPageIndex "-1") ValidatePageIndex (); if (CurrentPageIndex == -1) return; // prepare And run the command SQLCommand cmd = prepareCommand (countinfo); if (cmd == null) return; sqldataadapter adapter = new SqlDataAdapter (CMD); DataTable Data = new data (); adapter.fill (data); // Configuring data source assembly if (_dataSource == null) _dataSource = new PagedDataSource (); _dataSource.AllowCustomPaging = true; _dataSource.AllowPaging = true; _dataSource.CurrentPageIndex = 0; _dataSource.PageSize = ItemsPerPage; _dataSource.VirtualCount = countInfo.RecordCount; _dataSource. DataSource = Data.defaultView;} In Noncached mode, the PageDDataSource object does not provide the entire data source, so the total number of pages to be paid can not be calculated. Thereby, the AllowCustomPaging property must be tagged and the actual number of records in the data source is provided. Typically, the actual number is to retrieve the Select Count (*) query. This model is almost the same as DataGrid's custom paging. In addition, the current page index selected in the PagedDataSource object is usually 0, because one page record has been stored.
The implementation method of the SQLPAger control is introduced here. Let's introduce it to its method.
Use SQLPAGER controls
Assume that there is a sample page containing the ListBox control. To use a paging program, make sure the .aspx page registers the assembly of the control.
The tag of the control depends on the properties of the actual setting. The following tags are an rational example:
In addition to the page program, the page also contains a list box and a button. The list box will display the contents of each page; the button is only used for the first time fill the list box. This button has a clicking event handler, defined as follows.
Figure 2: SQLPAger control works with the ListBox control.
Use the DataList control to generate a more interesting example. The goal is to use the paging program to browse the personal record of each Northwind staff. This DataList is shown in the following list.
<% # databinder.eval (container.dataitem, "notes")%> td> tr> table> itemtemplate> ask: DATALIST> table The first line shows the name and position of the staff, then the photo, the photo is comment around the photo. The photo is retrieved using a specific .aspx page, returns JPEG data from the database.
The paging program can be placed anywhere in the page. In this example, it is placed above the partner DataList control and next to the partner control.
Figure 3: SQLPAGER Subject to the DataList control
Is it meaningful to use the SQLPAGR control with the DataGrid control? This is dependent on the situation. DataGrid has worked with an embedded paging engine based on the PagedDataSource object used herein. Therefore, if you need to make a single record collection displayed in a table format, you don't need to use SQLPAGER. However, for important / complex solutions, use these two controls together is not a strong idea. For example, if you want to add a DataGrid to the forward screen to display the order by the staff, you can place two related paging engines on the same grid page, one to paginist, another to scroll relevant orders .
summary
Don't do this type of application (web application, microsoft? Windows? Application or web service), you are hard to download and cache the entire data source to display. Sometimes the test environment will make you believe this solution is really great, it is very desirable. But the test environment will be misleaded. The size of the data source is very critical, the larger the scale of the application, the higher the size of the data source. In ASP.NET, only the DataGrid control has built-in paging feature. However, the paging engine is implemented by quite sampleized code, as long as a small amount of processing can be promoted and used for multiple different controls. This goal is achieved by the SQLPAger control described herein. It is concerned about downloading data, divides the data into multiple pages and displays them through the partner control. The control can retrieve and cache the entire data set, or query only several records you want to display in the selected page in SQL Server. I am talking about SQL Server, this is another focus. SQLPAGER can only be used for SQL Server, cannot be used to retrieve data via OLE DB or ODBC. You cannot use it to access Oracle or DB2 archive.
To generate a real generic SQL paging program component, you should form a data access layer and generate a factory class capable of creating connection, commands, and adapters using the appropriate data provider. In addition, pay attention to setting a paging engine for a variety of SQL sources is the worst approach. The methods described here are only available for SQL Server 7.0 and higher. TOP clauses have different characteristics in different environments. Using server cursors and temporary tables, it can be applied to a wide range of DBMS systems. But that will make the code more complicated.