All source code in ASP/ VbScript Ask a ASP/ VbScript Pro Discussion Forum Categories All jobs in ASP/ VbScript
Quick Search for:  in language:    
routine,will,create,paging,links,automates,ju
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 281,486. lines
 Jobs: 101. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login

NEW! LEARNING CENTER
Special educational offers, white papers, webcasts, podcasts

  NEW! Download Rational Performance Tester V8 (download now)
  NEW! Download Rational Functional Tester V8 (download now)
  NEW! Download Rational Service Tester for SOA Quality V8 (download now)
  NEW! Teleconference: Quality In Action - Using Rational Quality Manager with Functional, Performance and Web Service Testing Products (download now)
  NEW! Introducing IBM Rational AppScan Developer Edition – easing security testing by non-security professionals (download now)

 

 


Latest postings for ASP/ VbScript.
Click here to see a screenshot of this code!Mess Officer Management System (Sistem Pengurusan Mess Pegawai)
By Mohd Fauzi on 11/23

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!



 
 
   

Paging Function

Print
Email
 
VB icon
Submitted on: 9/1/2001 10:02:41 PM
By: Shannon Harmon 
Level: Intermediate
User Rating: By 1 Users
Compatibility:ASP (Active Server Pages)

Users have accessed this code 35754 times.
 
(About the author)
 
     This routine will create paging links for you. It automates the links for you, just pass the current page, the total amount of pages to it and it will do the rest.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    '**************************************
    ' Name: Paging Function
    ' Description:This routine will create p
    '     aging links for you. It automates the li
    '     nks for you, just pass the current page,
    '     the total amount of pages to it and it w
    '     ill do the rest.
    ' By: Shannon Harmon
    '
    'This code is copyrighted and has    ' limited warranties.Please see http://w
    '     ww.Planet-Source-Code.com/vb/scripts/Sho
    '     wCode.asp?txtCodeId=6875&lngWId=4    'for details.    '**************************************
    
    <%
    Public function Paging(ByVal intPage, ByVal intPageCount, ByVal intRecordCount)
    	'Customize me to your liking...
    	'Assumes that the paging request variable is named 'page'
    	Dim strQueryString
    	Dim strScript
    	Dim intStart
    	Dim intEnd
    	Dim strRet
    	Dim i
    	if intPage > intPageCount Then
    		intPage = intPageCount
    	ElseIf intPage < 1 Then 
    		intPage = 1
    	End if
    	
    	if intRecordCount = 0 Then
    		strRet = "No Records Found"
    	ElseIf intPageCount = 1 Then
    		strRet = "All Records Shown"
    	Else
    		For i = 1 To Request.QueryString.Count
    			if LCase(Request.QueryString.Key(i)) <> "page" Then
    				strQueryString = strQueryString & "&" 
    				strQueryString = strQueryString & Server.URLEncode(Request.QueryString.Key(i)) & "=" 
    				strQueryString = strQueryString & Server.URLEncode(Request.QueryString.Item(i))
    			End if
    		Next
    		For i = 1 To Request.Form.Count
    			if LCase(Request.Form.Key(i)) <> "page" Then
    				strQueryString = strQueryString & "&" 
    				strQueryString = strQueryString & Server.URLEncode(Request.Form.Key(i)) & "=" 
    				strQueryString = strQueryString & Server.URLEncode(Request.Form.Item(i))
    			End if
    		Next
    		if Len(strQueryString) <> 0 Then
    			strQueryString = "?" & Mid(strQueryString, 2) & "&"
    		Else
    			strQueryString = "?"
    		End if
    		strScript = Request.ServerVariables("SCRIPT_NAME") & strQueryString
    	
    		if intPage <= 10 Then
    			intStart = 1
    		Else
    			if (intPage Mod 10) = 0 Then
    				intStart = intPage - 9
    			Else
    				intStart = intPage - (intPage Mod 10) + 1
    			End if
    		End if
    		intEnd = intStart + 9
    		if intEnd > intPageCount Then intEnd = intPageCount
    	
    		strRet = "Page " & intPage & " of " & intPageCount & ": "
    	
    		if intPage <> 1 Then 
    			strRet = strRet & "<A href=""" & strScript
    			strRet = strRet & "page=" & intPage - 1 
    			strRet = strRet & """><<PREv</A> "
    		End if
    	
    		For i = intStart To intEnd
    			if i = intPage Then
    				strRet = strRet & "<B>" & i & "</B> "
    			Else
    				strRet = strRet & "<A href=""" & strScript
    				strRet = strRet & "page=" & i 
    				strRet = strRet & """>" & i & "</A>"
    				if i <> intEnd Then strRet = strRet & " "
    			End if
    		Next
    	
    		if intPage <> intPageCount Then
    			strRet = strRet & " <A href=""" & strScript
    			strRet = strRet & "page=" & intPage + 1 
    			strRet = strRet & """>Next>></A> "
    		End if
    	End if
    	
    	Paging = strRet
    End function
    'Test the function, input values would n
    '     ormally
    'be pulled from database recordset infor
    '     mation
    Dim intPage
    intPage = 1
    if Not IsEmpty(Request("page")) Then
    	if IsNumeric(Request("page")) Then
    		intPage = CLng(Request("page"))
    	End if
    End if
    Response.Write Paging(intPage, 25, 200)
    %>


Other 3 submission(s) by this author

 

 
 Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:
 
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
9/19/2001 8:41:14 AMsteve

Thank you for this code..been looking for something this simple..however, I am still unable to get it to work properly..I load the function with my recordset info Paging(intPage, ors.PageCount, ors.RecordCount) -- however, it will display all the records in the recordset, instead of paging..how do i setup my recordset loop for this to work?
appreciate any advice..thank you
(If this comment was disrespectful, please report it.)

 
9/20/2001 1:47:57 AMShannon

http://www.asp101.com/samples/db_paging.asp

Visit the above link and it will give you a good example on how to setup the recordset for paging. The routine I wrote will just create the links for you automatically to make it easier. Once you setup your recordset for paging, you can use this function to allow the user to move through the pages without thinking about it.
(If this comment was disrespectful, please report it.)

 
12/25/2001 1:11:10 PMShannon Harmon

I uploaded a working sample with a database for learning how to use this function, you can find it here...

http://www.pscode.com/xq/ASP/txtCodeId.7079/lngWId.4/qx/vb/scripts/ShowCode.htm
(If this comment was disrespectful, please report it.)

 
7/9/2002 11:48:26 AMBianca

I used this code and all seems to be working well except, when I click on the following pages, the query does not carry itself over...and then returns the entire database instead of the next 10 query specific results. any suggestions? I am using a mulitple selection search.
(If this comment was disrespectful, please report it.)

 
11/14/2003 5:24:31 PM

The link you furnished to your sample:
http://www.pscode.com/xq/ASP/txtCodeId.7079/lngWId.4/qx/vb/scripts/ShowCode.htm
Doesn' t work. Is there another link for us?
Thanks,
Chalmers
(If this comment was disrespectful, please report it.)

 
11/15/2003 12:02:44 AMShannon Harmon

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=4&txtCodeId=7079

I don't know where you found that link, but the above link works just fine.

Take care!
(If this comment was disrespectful, please report it.)

 
10/25/2005 12:20:11 AMLil

Extremely helpful! Not too difficult for the intermediate coder such as moi to figger out, either, along with your tutorial at asp101.
(If this comment was disrespectful, please report it.)

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
To post feedback, first please login.


 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | Open Letter from Moderators | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997-2008 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.   Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.