ASP. NET -- true/false Paging

Source: Internet
Author: User

ASP. NET -- true/false Paging

The so-called paging refers to dividing all the content to be displayed into n pages for display. Why should we use pagination instead of displaying all of them directly? This is like a book. We can use a piece of paper to write all the contents of the book, but this is not actually the case. We split the web page into one page. In fact, it is largely for the user to consider, greatly facilitating the user.

There are two types of paging: True paging and false paging.

The "false" of the false paging is that I have taken all the data out, but I only give some control when displaying it to achieve the paging effect.

The "truth" of a real paging is that all data is not taken out at a time, but the page on which the real user can view the required content in the database.

False pagination:

In ASP. NET, we often use GridView and Repeater to bind data sources and display the data found from the database. Let's take the GridView as an example to see how fake pages are implemented.

First, add the GridView on the page. Set the number of entries that can be displayed by page or by page, that is, AllowPaging = True and PageSize = 6. (6 records are displayed on each page ,)

When running the interface, the page status is displayed. However, when you click the button on page 1, The PageIndexChanging event is triggered. It is triggered when you click a page navigation button, but before the GridView control handles paging operations.

 

Public partial class Test: System. Web. UI. Page {protected void Page_Load (object sender, EventArgs e) {// The bound data if (! Page. IsPostBack) {GridView1.DataSource = new NewsManager (). SelectAll (); // layers are used here, which can be understood as tables in the bound database. GridView1.DataBind () ;}// trigger the pagination event protected void GridView1_PageIndexChanging (object sender, GridViewPageEventArgs e) {GridView1.PageIndex = e. newPageIndex; GridView1.DataSource = new NewsManager (). selectAll (); GridView1.DataBind ();}}
In this way, you can implement false paging.

 

Real paging:

A paging control AspNetPager is used here.

First, add the control.

Right-click the -- tab in the toolbox

Click Browse and find AspNetPager. dll.

In this way, the control is displayed in the toolbox.

Drag it to the design interface, such:

After the page control is added, set the number of entries and the maximum number of records on each page. When the page number is changed, the PageChanged event is executed. StartRecordIndex and EndRecordIndex are the start and end rows respectively. Using these two parameters, you can easily retrieve data from the database page by page. We will not go into details here.

 

Compare the two paging methods:

Real pages interact with the background many times, but they still maintain high efficiency in the face of massive data and provide a good user experience. False PagingOn the contrary.

 

Appendix:

Paging statements in SQL

 

Select top number of records per page (PageSize) * from topic where id not in (select top (current page number-1) × number of records displayed per page id from topic order by id desc) order by id desc

AspNetPager Page Control

 

 

Related Article

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.