The first time I wrote the paging function, the first time I wrote the paging function.

Source: Internet
Author: User

The first time I wrote the paging function, the first time I wrote the paging function.

I started my internship in a software company in last June, and now I have worked on three projects in total. The first two of these projects were both half-way started with the people in the group, because it is just half-done, it is not very clear about some things, and it is also a webform project. Starting from the middle and late last month, I started a new project from the beginning. The new project was made with MVC4, so I had to learn MVC from the beginning, recently, all the pages of the project have been set up (the pages have been written and written again), and the data display page has to be started. Because the project uses bootstrap as the foreground, I also use the bootstrap paging Control for paging. However, because this is the first time I write a page, I also need to control the display of the following page number and the display of the corresponding data. In addition, I didn't know much about the page number and didn't read anyone's Page code, I have not fully figured out how to control the display of the page number, so I started to write it in a hurry. As a result, many errors have occurred and I cannot get the desired results, in addition, I had a problem with my thinking at the beginning, and I didn't think about it in another way. I finally got stuck for a long time, and finally thought about it for a while, achieving the desired effect. The result is that the page number is manually controlled. You can decide how many pages are displayed on the page. When the cyclic I is equal to the url parameter, add the active class to li. The current page number is displayed, when the current page contains more than 3rd pages, a ellipsis is given to the location of the first page, indicating that there are still pages, that is, Data. There are three pages in the middle and a ellipsis in the end. Here we actually use two for loops, the first for loop. When the page number is less than or equal to 3, we loop out the page numbers from 1 to 3, and add the ellipsis after the loop.

Before the second for loop, judge that when the page number is greater than 3, the first li shows the ellipsis, and then starts the loop. The cycle starts from the current page number minus 2 until the total page number ends, there are three pages in the middle, followed by a ellipsis. I wrote this essay to record my ideas so as not to make mistakes in the future. The previous ideas are stuck here. At the same time, I also remind myself that when a road cannot be reached, I think it is impossible to think about it. Maybe the desired result can be achieved. Don't get stuck too long in one way, try other ideas and there is always a solution to the problem. In short, continue to learn knowledge and write code well.

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.