Supplementary description on massive paging)

Source: Internet
Author: User

Because"Bigfocus"Comrade has always had a special liking for the massive paging, especially when he did not respond to his small request for more than half a month. He felt very embarrassed, therefore, we intend to provide additional explanations on the massive paging volumes that have previously been brilliant.

 

First, I am learning ASP. net, based on the massive pages of the ASP version, the new stuff is designed to minimize the SQL load when there is a large amount of records. At that time, I didn't know what MVC is or what dataset is cached. I knew that datareader () was a kind of thing, and I was very naive to write ASP for C # with Rs. Read. Now it seems that in the current situation, massive paging indeed contributed to personal development, but with ASP. with the in-depth understanding of net, massive paging has completed its mission and gradually exited the stage of history.

To put it bluntly, the core idea of massive paging is to "Combine SQL statements and only read the required records ". I use statements like "select Top N" to obtain data. The problem is that I have to write a lot of places like where and on the logic layer or even the presentation layer. Code clutter lacks aesthetic, and worse, it is difficult to write data binding (not impossible, but troublesome ).

The following code is an implementation of a page flip list page:

String sqlfield = "ID, indexid, title, createdate"; // Field
String sqlfrom = "from userv_article ";
String sqlorder = "order by Istop DESC, Id DESC"; // sort
String pagestr = request ["page"]; // current page number
Int pagesize = 15; // number of records per page

String sqlwhere = ""; // where when conditions exist
String sqland = ""; // and when conditions exist
String sqlcondition = ""; // Condition
Sqlwhere = "where ";
Sqland = "and ";
Sqlcondition = "indexid =" + request ["indexid"] + "and isauditing = 1 and isdel = 0 and createdate <'" + datetime. now. tostring () + "'";//

Stackpage sp = new stackpage ();
Int recordcount = sp. srecordcount (sqlfrom, sqlwhere, sqlcondition); // obtain the total number of records
Int pagecount = sp. spagenum (pagesize, recordcount); // obtain the total number of pages
Int page = sp. spagenow (pagestr, pagecount); // obtain the current page number.
Int countnum = sp. scountnum (pagesize, recordcount, page, pagecount); // obtain the number of entries displayed on the current page.
If (countnum = 0)
{
Limessage. Visible = true;
}
Else
{
Sqldatareader rsarticle = sp. sshowpage (sqlfield, sqlfrom, sqlwhere, sqland, sqlcondition, sqlorder, page, recordcount, pagesize); // obtain the paging Dataset
Rptlist. datasource = rsarticle;
Rptlist. databind ();
Viewstate ["pagecount"] = pagecount. tostring ();
}
The main function is to obtain the record set of the specified field and generate the number of pages on the foreground. At that time, I still had no idea how to write the control attributes, but I had no choice but to use viewstate to pass the page number value. Haha was a real joke.

The following is the sample code of massive paging. The compressed sample code package is: click I download.

Usage:

1. Download to learn about compression

2. Create a virtual directory in the WWW directory

3. The data directory is a MSSQL database file. We recommend that you use SQL2000 for additional operations.

4. Configure the connection string in Web. config.

5. Try browsing. If you have any questions, leave a message below this post to ask questions.

PS:After reading the sample code, I hope you will not laugh at me. This Code seems to be disgusting all the time, but it is a record of my years. Some friends especially want to see it, I will send it to you for targeted purposes ~~~~~

The Virgos have super perfectionist, especially the code cleanliness, which is super negative for the previous Code and can easily lead to the impulse of refactoring, as a result, we have been counting the various drawbacks of massive page flip for a long time (although it does exist ).

If you have a better way of paging or something, you are welcome to discuss it together.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.