ASP Digital Paging Effect Code _ Application Skills

Source: Internet
Author: User
Tags prev
The recent web site revision just found that the original page without numbers, only the first page up the next page and then select the jump, are more popular before, and now more popular is the number of pages in the middle, just research and share, the need for friends can refer to the

Effect:



The core code abroad:

Copy Code code as follows:

<%
' Digg style pagination script in ASP. Written by Moazam ... http://www.moazam.com/2007/03/30/asp-digg-style-pagination-script/

function getpaginationstring (page, TotalItems, limit, adjacents, targetpage)
' Defaults
If not IsNumeric (adjacents) Then adjacents = 1-End If
If not isnumeric (limit) then limit = "End If"
If not isnumeric (page) then page = 1-End If
If TargetPage = "" Then TargetPage = "/" End If
Margin = ""
Padding= ""
' Other VARs
Prev = page-1 ' previous page is page-1
nextPage = page + 1 ' nextPage page is page + 1
LastPage = Ceil (totalitems, limit) ' lastpage is = total items/items/page, rounded up.
LPM1 = lastpage-1 ' last page minus 1
' Now we apply our rules and draw the pagination object.
' we ' re actually saving the code to a variable into case We want to draw it more than once.

pagination = ""
If LastPage > 1 Then

pagination = pagination & "<div class=" "Pagination" ""
If margin <> "" OR padding <> "" Then
pagination = pagination & "style=" ""
If margin <> "" Then
pagination = pagination & "Margin:margin"
End If
If padding <> "" Then
pagination = pagination & "Padding:padding"
End If
pagination = pagination & "" "
End If
pagination = pagination & ">"

' Previous button
If page > 1 Then
pagination = pagination & "<a href=" "&targetpage&" &page= "&prev&" ">Prev</a>"
Else
pagination = pagination & "<span class=" "Disabled" ">Prev</span>"
End If
' Pages
If LastPage < 7 + (Adjacents * 2) Then ' not enough pages to bother breaking it up

For counter = 1 to LastPage

If counter = page Then
pagination = pagination & "<span class=" "Current" ">" &counter& "</span>"
Else
pagination = pagination & "<a href=" "&targetpage&" "&" &page= "&counter&" ">" & counter& "</a>"
End If
Next
ElseIf lastpage >= 7 + (adjacents * 2) Then ' enough pages to hide some
' Close to beginning only hide later pages
If page < 1 + (Adjacents * 3) Then
For counter = 1 to (4 + (Adjacents * 2))-1
If counter = page Then
pagination = pagination & "<span class=" "Current" ">" &counter& "</span>"
Else
pagination = pagination & "<a href=" "&targetpage&" &page= "&counter&" ">" &counter & "</a>"
End If
Next
pagination = pagination & "..."
pagination = pagination & "<a href=" "&targetpage&" "&" &page= "&lpm1&" ">" &lpm1 & "</a>"
pagination = pagination & "<a href=" "&targetpage&" "&" &page= "&lastpage&" ">" & lastpage& "</a>"
' In middle hide some front and some
ElseIf LastPage-(adjacents * 2) > Page > (adjacents * 2) Then
pagination = pagination & "<a href=" "&targetpage&" &page=1 "" >1</a> "
pagination = pagination & "<a href=" "&targetpage&" &page=2 "" >2</a> "
pagination = pagination & "..."
For counter = (page-adjacents) to (page + adjacents)
If counter = page Then
pagination = pagination & "<span class=" "Current" ">" &counter& "</span>"
Else
pagination = pagination & "<a href=" "&targetpage&" &page= "&counter&" ">" &counter & "</a>"
End If
Next
pagination = pagination & "..."
pagination = pagination & "<a href=" "&targetpage&" &page= "&lpm1&" ">" &lpm1& " </a> "
pagination = pagination & "<a href=" "&targetpage&" page= "&lastpage&" ">" &lastpage & "</a>"
' Close to end only hide early pages
Else
pagination = pagination & "<a href=" "&targetpage&" &page=1 "" >1</a> "
pagination = pagination & "<a href=" "&targetpage&" &page=2 "" >2</a> "
pagination = pagination & "..."
For counter = (LastPage-(1 + (Adjacents * 3)) to LastPage
If counter = page Then
pagination = pagination & "<span class=" "Current" ">" &counter& "</span>"
Else
pagination = pagination & "<a href=" "&targetpage&" &page= "&counter&" ">" &counter & "</a>"
End If
Next
End If
End If
' NextPage button
If page < counter-1 then
pagination = pagination & "<a href=" "&targetpage&" &page= "&nextPage&" "" >next</a > "
Else
pagination = pagination & "<span class=" "Disabled" ">Next</span>"
End If
pagination = pagination & "</div>" & vbNewLine
End If
Getpaginationstring = pagination
End Function
function ceil (dividend, divider)
if (dividend mod divider) = 0 Then
Ceil = Dividend/divider
ELSE
Ceil = Int (dividend/divider) + 1
End If
End Function
' Test script code
page = 1
If Request ("page") <> "then
Page=cint (Request ("page")
End If
PS = getpaginationstring (page, 1500, 2, "Pagination.asp?foo=bar")
Response.Write ("<br/><br/><br/><br/><br/><br/><br/><br/>" & ps
%>



Full Package code: Pagination (jb51.net). rar

See some dizziness, or look at the simple bar, ASP and PHP thinking about Ah, reference to the Dedecms modification method

Effect Chart:

Core code:

Copy Code code as follows:

Ps=cint (PageNo)-2
If Ps<1 Then
Ps=1
End If
PE=CLNG (PageNo) +5
If Pe>mpage then Pe=mpage
For I=ps to PE
If I=pageno Then
lb=lb& "<strong>" &i& "</strong>"
Else
lb=lb& "<a href=" "/list/list_" &theid& "_" &i& ". htm" ">" &i& "</a>"
End If
Next

Complete code:

Copy Code code as follows:

Pageno=cint (CurrentPage)
If CInt (pageno) >1 Then
lb=lb& "<a href=/list/list_" &theid& "_1.htm title=" "Home" "> Home </a>"
Else
lb=lb& "<a href= ' # ' > Home </a>"
End If
If CInt (PageNo) >1 and CInt (PageNo) Then
lb=lb& "<a href=/list/list_" &theid& "_" &pageno-1& ". htm title=" "prev" "> Page </a>"
Else
lb=lb& "<a href= ' # ' > Prev </a>"
End If
Ps=cint (PageNo)-2
If Ps<1 Then
Ps=1
End If
PE=CLNG (PageNo) +5
If Pe>mpage then Pe=mpage
For I=ps to PE
If I=pageno Then
lb=lb& "<strong>" &i& "</strong>"
Else
lb=lb& "<a href=" "/list/list_" &theid& "_" &i& ". htm" ">" &i& "</a>"
End If
Next

If CInt (PageNo) <mpage and mpage>1 Then
lb=lb& "<a href=/list/list_" &theid& "_" &pageno+1& ". htm title=" "Next" "> next page </a>"
Else
lb=lb& "<a href= ' # ' > next page </a>"
End If
If CInt (PageNo) < mpage Then
lb=lb& "<a href=/list/list_" &theid& "_" &mpage& ". htm title=" "Last" "> Last </a>"
End If

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.