.. Net. compared with the predecessor of net, ADO has greatly improved the performance, but operations are also complicated. In the ASP era, use the pagesize and absolutepage of the recordset to perform data paging. net, the recordset object is gone, instead of dataset/datatable, without pagesize/absolutepage, paging becomes a very headache.
All ASP. NET tutorials will show you how to use the DataGrid Control for post-based paging. I have never used it in practice after I have completed this example. There are two reasons:
- CodeToo complicated;
- URL pagination is not supported, which is not conducive to search engines and debugging and is not subject to high standards.
We recommend that you do not use this paging function.
Can ASP. NET be paginated as easily as asp? The answer is yes. You need to use the pagedatasource class. Here is a complete tutorial for your reference, a master blog.
It is convenient to use pagedatasource, but it also has a fatal drawback, that is, the performance is reduced, and a 10000 data table is occasionally ASP/asp. net (DataGrid)/asp. net (pagedatasource) Three paging speed tests, the results are respectively 600 MS-700 ms/500 ms/900 ms-1000 ms, the pagedatasource paging speed is actually slower than ASP, depressed, this is probably because of secondary data binding. You can test it on your own to see if it is the same as my test results.
The essence is here ......
To improve the paging performance, you must use custom paging. First, let's take a look at what parameters are required for traditional ASP paging?
- Pagesize (number of records per page)
- Recordcount (total number of records)
- Pagecount (total number of pages)
- Absolutepage (absolute page ).
Back to ASP. NET, let's take an example. What about/newslist. asp? Page = 3. You can do this:
- Int pagesize = 20; // defines the number of records displayed on each page
- Int recordcount = "select count (*) from News"; // This sentence is incomplete and can be improved on your own.
- Int pagecount = recordcount/pagesize; // the total number of pages is calculated.
- Int currentpage = convert. toint32 (request. querystring ["page"]. tostring ());
The key point is that you need to fill the data in dataset. Pay attention to this technique:
Dadapter. Fill (dset, (currentpage-1) * pagesize, pagesize, "table ");
This statement can fill the dataset with data at the specified position, so that the paging effect can be achieved.
After testing, this paging reduces the server memory consumption due to the amount of data filled in dataset, and the page execution speed is approximately 120 ms-170 Ms.
Related connections:
Use the pageddatasource class to display datalist and repeater controls by page.
Asp.net provides three powerful list controls: the DataGrid, datalist, and repeater controls, which have higher style customization compared with the DataGrid, datalist, and repeater controls, many times we like to use the datalist or Repeater control to display data. However, repeater and datalist do not have the paging function and are sometimes inconvenient.
The pageddatasource class encapsulates the properties of the DataGrid control so that the DataGrid Control can execute pagination. It is a data container. We first read the data from the database and put it in this container, then, set the container property to retrieve part of the data on the page to be displayed, and then bind the data to the display control on the page.
The following example shows the data paging list implemented by the Repeater control and hyperlink control combined with the pageddatasource class.
Data function implementationSource code:
// reference the pagination class
pageddatasource PDS = New pageddatasource ();
PPS. datasource = DT. defaultview; // set the data source (datatable type)
PSP. allowpaging = true ;
// The number of rows displayed on the page
PPS. pagesize = 18;
// Set the current page
If(Pageindex <1) pageindex = 1;
PPS. currentpageindex = Pageindex-1;
Rpt_newslist.datasource = PDS;
Rpt_newslist.databind ();
// Display the page number
Ltl_recordcount.text=PPS. performancecount. tostring ();
Ltl_pagecount.text=PPS. pagecount. tostring ();
Ltl_pageindex.text=Pageindex. tostring ();
Ltl_jump.text=Jump_list (PPS. pagecount, pageindex, l_manage );
// Display up and down pages (the parameters following the URL are defined as needed)
Lbn_first.tooltip= "Jump to homepage" ;
Lbn_first.navigateurl = request. currentexecutionfilepath + "? Org_id =" + Rochelle manage + "& Page = 1" ;
Lbn_prev.tooltip= "Jump to previous page" ;
Lbn_prev.navigateurl = request. currentexecutionfilepath + "? Org_id =" + Rochelle manage + "& Page =" + (Pageindex-1 );
Lbn_next.tooltip = "Jump to next page" ;
Lbn_next.navigateurl = request. currentexecutionfilepath + "? Org_id =" + Rochelle manage + "& Page =" + (Pageindex + 1 );
Lbn_last.tooltip = "Jump to the last page" ;
Lbn_last.navigateurl = request. currentexecutionfilepath + "? Org_id =" + Rochelle manage + "& Page =" + PDs. pagecount. tostring ();
// Determine the link Display Mode
If (Pageindex <= 1 & tp.pagecount <= 1)
{
Lbn_first.navigateurl = "" ;
Lbn_prev.navigateurl= "" ;
Lbn_next.navigateurl = "" ;
Lbn_last.navigateurl = "" ;
}
If (Pageindex <= 1 & tp.pagecount> 1)
{
Lbn_first.navigateurl = "" ;
Lbn_prev.navigateurl = "" ;
}
If (Pageindex> = maid. pagecount)
{
Lbn_next.navigateurl = "" ;
Lbn_last.navigateurl = "" ;
}
/// <Summary>
/// Calculate the page Jump
/// </Summary>
/// <Param name = "pagecount"> page count </param>
/// <Returns> string </returns>
Private String Jump_list ( Int Pagecount, Int Pageindex, Long Rochelle manage)
{
Stringbuilder sb = New Stringbuilder ();
SB. append ( "<Select id = \" page_jump \ "name = \" page_jump \ "onchange = \" window. Location = '" + Request. currentexecutionfilepath + "? Page = '+ this. Options [This. selectedindex]. Value +' & org_id =" + Rochelle manage + "'; \">" );
For ( Int I = 1; I <= pagecount; I ++)
{
If (Pageindex = I)
SB. append ( "<Option value = '" + I + "'Selected>" + I + "</Option>" );
Else
SB. append ("<Option value = '" + I + "'>" + I + "</Option>" );
}
SB. append ( "</SELECT>" );
ReturnSB. tostring ();
}
Dynamic Display
Some public attributes of the pageddatasource class:
Allowcustompaging gets or sets the value indicating whether to enable custom paging.
Allowpaging gets or sets the value indicating whether to enable pagination.
Count to obtain the number of items to be used from the data source.
Currentpageindex gets or sets the index of the current page.
Datasource obtains or sets the data source.
Cececount gets the number of items in the data source.
Firstindexinpage gets the first index on the page.
Iscustompagingenabled gets a value indicating whether to enable custom paging.
Isfirstpage gets a value indicating whether the current page is a homepage.
Islastpage gets a value indicating whether the current page is the last page.
Ispagingenabled gets a value indicating whether to enable paging.
Isreadonly gets a value indicating whether the data source is read-only.
Issynchronized gets a value indicating whether to synchronize access to the data source (thread safety ).
Pagecount obtains the total number of pages required for all items in the data source.
Pagesize gets or sets the number of items to be displayed on a single page.
Virtualcount gets or sets the actual number of items in the data source when custom pages are used.