Question

ASP paging for displaying certain set of pages at a time

Asked by: yogman

i want code for paging for ex.
if i have 400 records then for 1st 10 records i will have
1 2 3 4 5 6 7 8 9 10 next>>
on clicking of next>> i will display 101th record with 11th page
<<prev 11 12 13 14 15 16 17 18 19 20 next>>
and so on.
i tried but cud not get

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-04-26 at 03:23:09ID20597068
Tags

asp

Topic

Active Server Pages (ASP)

Participating Experts
4
Points
70
Comments
16

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Hiding << prev | next >> records
    I have a photo gallery where I am linking to the previous photo and next photo with links like: << prev | next >> How can I hide << prev or next >> if there are no previous photos in the database or next photos in the database? Thanks for any ...
  2. Displaying records in multiple pages by giving links to First,…
    Hi, The question I have is a common feature which appears in most of the websites. I am using Oralce8.1.7 as my back-end and ASP as front-end. I have huge number of records in one of my tables from which I need to get and display records on my page along with links at the ...
  3. ASP SELECT/CASE Problem. Code does not go to Next/…
    Hello Experts, I am trying use Next and Prev button to display my fetched record. Code below works for Last, First and initial first record. For Prev and Next it only goes upto next record where I have 4 record fetched and I have tested it. For first time clicking the Next i...
  4. Next and Prev Links with SQL and ASP
    Hi, I have a page showimg.asp that displays the image from database and it needs to have a Next Prev buttons. So this page requests ID and displays a relative image pulled from the database. Next button is currently works with ID+1 formula and Prev with ID-1. Obviously, it ...
  5. How to do Prev | Next on a website.
    I am still relatively new to website development. I am using Dreamweaver MX and the site is hosted on a Unix platform. There is a feature I would like to implement. Often I read forums and I like the prev | next functionality. I often read about 50 entries before gettin...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: hongjunPosted on 2003-04-26 at 03:23:49ID: 8400415

 

by: yogmanPosted on 2003-04-26 at 04:11:03ID: 8400494

i saw that ex. in that ex. when u click on next, 2nd page is open and so on..what i want is when i click on next ,the pages open should be 4 5 6  etc,best ex. is of google search.click on next in it.
thnks for the comment

 

by: ASPGuruPosted on 2003-04-26 at 04:24:38ID: 8400509

google does exactly this... it shows the next page... when you're on the first page it shows the second upon clicking "next"...

what you want is not next and prev links, but +10 and -10 links... right?

this also can be done with the approach described in the above link...

read the example and understand it, then you'll know how to solve this !


ASPGuru

 

by: yogmanPosted on 2003-04-26 at 04:46:31ID: 8400543

ur right i want +10 -10 links
i m following some other ex.
http://www.xefteri.com/articles/16jan2003/default.aspx
theres a function getPagingHTML() in clsDatabase.asp
i m trying but not getting the exact effect.

 

by: ASPGuruPosted on 2003-04-26 at 04:52:02ID: 8400552

post the code you already have and tell us what's the problem with it.. so we can help you...

ASPGuru

 

by: yogmanPosted on 2003-04-26 at 04:53:22ID: 8400555

ur right i want +10 -10 links
i m following some other ex.
http://www.xefteri.com/articles/16jan2003/default.aspx
theres a function getPagingHTML() in clsDatabase.asp
i m trying but not getting the exact effect.

 

by: yogmanPosted on 2003-04-26 at 05:06:54ID: 8400578

'create the navigation links for paging
Public Function GetPagingHTML()
  Dim strOutput
  Dim strThisPage
  Dim i,j,k,setp,myval,i_PageSet
 i_PageSet = 5 'show 5 pages at a time
  strThisPage = Request.ServerVariables("SCRIPT_NAME")
  strOutput = "Result Page:"
  If i_CurrentPage <> 1 Then
    strOutput = strOutput & "&nbsp;&nbsp;<a href=""" & strThisPage _
 & "?StartingRecord=" & ((i_CurrentPage - 1)* i_RecordsPerPage) - i_RecordsPerPage + 1 _
 & """>Previous</a>&nbsp;&nbsp;"
 End If
j= 1
if i_TotalPages > i_PageSet then
 i_TotalPages = i_PageSet
end if
if i_CurrentPage <= i_PageSet then
 i_TotalPages = i_PageSet
 j= i_CurrentPage
end if
For i = j To i_TotalPages
 If i <> i_CurrentPage Then
  strOutput = strOutput & "&nbsp;&nbsp;<a href=""" &  strThisPage _
& "?StartingRecord=" & (i * i_RecordsPerPage) -i_RecordsPerPage + 1 _
& """>" & i & "</a>&nbsp;&nbsp;"
Else
strOutput = strOutput & "&nbsp;&nbsp;<b>" & i & "</b>&nbsp;&nbsp;"
End If
k=(i * i_RecordsPerPage) - i_RecordsPerPage + 1
Next
'If i_CurrentPage <> i_TotalPages Then
strOutput = strOutput & "&nbsp;&nbsp;<a href=""" & strThisPage _
& "?StartingRecord=" & k + i_RecordsPerPage & "&setpage="&i&""">Next</a>&nbsp;&nbsp;"
'End If

GetPagingHTML = strOutput
  End Function
in the above function i have prob. within the for loop
for i=j here as the value of j is assigned to current page the previous value disappears..if i click on page 2 ,1 disappears. i know the prob. but dunno how to resolve it

 

by: ASPGuruPosted on 2003-04-26 at 05:49:34ID: 8400660

i like that you use a function, but you seem to use global variables... this is not recommended...
just use the variables you get as parameters and local variables... so you easily reuse the code...

so try this... there may be bugs in this... i wrote it out of my head and haven't tested it:

<%
'set the following variables:
i_CurrentPage
i_TotalPages
i_PageSet = 5 'show 5 pages at a time
s_BaseURL = Request.ServerVariables("SCRIPT_NAME") & "?page="

'then:
Response.Write getPagingHTML(s_BaseURL, i_CurrentPage, i_TotalPages, iPageSet)

Public Function GetPagingHTML(sURL, iCur, iTot, iSet)
     Dim sOut, i, iCurSet, iTotSet, iFirst
     
     sOut = ""
     iCurSet = int( (iCur-1)/iPageSet )
     iTotSet = int( (iTot-1)/iSet )
     iFirst = iCurSet*iSet + 1
     
     if iCurSet>0 then
          sOut = sOut & "<a href=""" & sURL & (iCur-iSet) & """>&lt;-" & iSet & "]</a> "
     end if
     
     for i = 0 to iSet-1
          if (iFirst+i)=iCur then
               sOut = sOut & "[" & (iFirst+i) & "] "
          else
               sOut = sOut & "<a href=""" & sURL & (iFirst+i) & """>[" & (iFirst+i) & "]</a> "
          end if
     next
     
     if iCurSet<iTotSet then
          sOut = sOut & "<a href=""" & sURL & (iCur+iSet) & """>[+" & iSet & "&gt;</a>"
     end if

     GetPagingHTML = sOut
 End Function
%>


ASPGuru

 

by: yogmanPosted on 2003-04-26 at 05:57:46ID: 8400676

'create the navigation links for paging
Public Function GetPagingHTML()
  Dim strOutput
  Dim strThisPage
  Dim i,j,k,setp,myval,i_PageSet
 i_PageSet = 5 'show 5 pages at a time
  strThisPage = Request.ServerVariables("SCRIPT_NAME")
  strOutput = "Result Page:"
  If i_CurrentPage <> 1 Then
    strOutput = strOutput & "&nbsp;&nbsp;<a href=""" & strThisPage _
 & "?StartingRecord=" & ((i_CurrentPage - 1)* i_RecordsPerPage) - i_RecordsPerPage + 1 _
 & """>Previous</a>&nbsp;&nbsp;"
 End If
j= 1
if i_TotalPages > i_PageSet then
 i_TotalPages = i_PageSet
end if
if i_CurrentPage <= i_PageSet then
 i_TotalPages = i_PageSet
 j= i_CurrentPage
end if
For i = j To i_TotalPages
 If i <> i_CurrentPage Then
  strOutput = strOutput & "&nbsp;&nbsp;<a href=""" &  strThisPage _
& "?StartingRecord=" & (i * i_RecordsPerPage) -i_RecordsPerPage + 1 _
& """>" & i & "</a>&nbsp;&nbsp;"
Else
strOutput = strOutput & "&nbsp;&nbsp;<b>" & i & "</b>&nbsp;&nbsp;"
End If
k=(i * i_RecordsPerPage) - i_RecordsPerPage + 1
Next
'If i_CurrentPage <> i_TotalPages Then
strOutput = strOutput & "&nbsp;&nbsp;<a href=""" & strThisPage _
& "?StartingRecord=" & k + i_RecordsPerPage & "&setpage="&i&""">Next</a>&nbsp;&nbsp;"
'End If

GetPagingHTML = strOutput
  End Function
in the above function i have prob. within the for loop
for i=j here as the value of j is assigned to current page the previous value disappears..if i click on page 2 ,1 disappears. i know the prob. but dunno how to resolve it

 

by: ASPGuruPosted on 2003-04-26 at 06:20:17ID: 8400738

use the link at the top left to refresh the page, so you don't post your messages multiple times...

ASPGuru

 

by: yogmanPosted on 2003-04-27 at 23:17:49ID: 8410387

i tried that code but in vain.
if any one has fully tested code pls give it to me,coz i dont have time to look in the code n manipulate it.
thnks in advance.

 

by: ASPGuruPosted on 2003-05-01 at 05:18:09ID: 8435048

i also don't have time to fully debug the code... at least not for 70pts...

you have a good start here...
i'm willing to help people who help themselves...
this is not a free coding service!


ASPGuru

 

by: yogmanPosted on 2003-05-03 at 00:21:02ID: 8449312

i have created 2 function getpaginghtml() & getpaginghtml1()..i use getpaginghtml1() when i click on next>>..here i pass some parameters to identify ...this works only for 2 sets of pages..like 1 2 3 next>> ,when i click on next>>  i get another pageset  4 5 6 next>> but again when i click on next>> i get the same listing.

Public Sub DisplayResults()
      Dim arrResults
      Dim strOutput
      Dim rowCounter
      Dim colCounter
      Dim numCols
      Dim numRows
      Dim strBgColor
      Dim thisField
      Dim showBlank
      Dim showNull
      dim getpagingout
      'define variables
      showBlank = "&nbsp;"
      showNull = "-null-"
      'default value for records per page
      If i_RecordsPerPage = "" Then
            i_RecordsPerPage = 2
      End If
      'call internal function
      arrResults = GetRecordArray(i_RecordsPerPage)
      '#of rows and columns
      numCols = UBound(arrResults, 1)
      numRows = UBound(arrResults, 2)
      strOutput = "<table border=""1"" cellpadding=""" _
            & i_CellPadding & """ cellspacing=""" & i_CellSpacing & """ " _
            & "borderColorLight=""#666666"" borderColorDark=""#ffffff"">" _
            & "<tr><td valign=""top"" colspan=""" & (numCols + 1) _
            & """ align=""center"" bgcolor=""#CCCCCC"">" _
            & GetRecordPositionHTML() & "</td></tr>" _
            & "<tr>" & i_Titles & "</tr>"
      For rowCounter = 0 To numRows
            If rowCounter Mod 2 Then
                  strBgColor = i_AlternateRowColor
            Else
                  strBgColor = i_RowColor
            End If
            strOutput = strOutput & "<tr>" & vbcrlf
            For colCounter = 0 To numCols
                  thisField = arrResults(colCounter,rowCounter)
                  If IsNull(thisfield) Then
                        thisField = showNull
                  End If
                  If Trim(thisfield) = "" Then
                        thisField = showBlank
                  End If
                  strOutput = strOutput & "<td valign=""top"" bgcolor=""" & strBgColor & """>" _
                        & thisField & "</td>" & vbcrlf
            Next
            strOutput = strOutput & "</tr>" & vbcrlf
      Next


      If (i_TotalPages > 1) Then
            strOutput = strOutput & "<tr><td valign=""top"" align=""left"" colspan=""" _
                  & (numCols + 1) & """ bgcolor=""#cccccc"">" & GetPagingHTML & "</td></tr>"
      End If
      strOutput = strOutput & "</table>"
      Response.Write(strOutput)
  End Sub

Public Function GetPagingHTML()
      Dim strOutput
      Dim strThisPage
      Dim pageset,newstartrecord
      pageset=3
      Dim i

      newstartrecord = i_RecordsPerPage * pageset + 1

      strThisPage = Request.ServerVariables("SCRIPT_NAME")
      strOutput = "Result Page:"
      if not request("ispageset") = "" and cbool(request("ispageset")) then
            GetPagingHTML = GetPagingHTML1()
      else

      'If i_CurrentPage <> 1 Then
      'response.write(i_CurrentPage & "--"& pageset)
      dim strec
       If i_CurrentPage > pageset then
       strec = pageset * i_RecordsPerPage
            strOutput = strOutput & "&nbsp;&nbsp;<a href=""" & strThisPage _
                  & "?StartingRecord=" & strec &"&ispageset=true"">Previous</a>&nbsp;&nbsp;" '((i_CurrentPage - 1)* i_RecordsPerPage) - i_RecordsPerPage + 1 _

      End If
      For i = 1 To pageset
            If i <> i_CurrentPage Then
                  strOutput = strOutput & "&nbsp;&nbsp;<a href=""" & strThisPage _
                        & "?StartingRecord=" & (i * i_RecordsPerPage) - i_RecordsPerPage + 1 _
                        & """>" & i & "</a>&nbsp;&nbsp;"
            Else
                  strOutput = strOutput & "&nbsp;&nbsp;<b>" & i & "</b>&nbsp;&nbsp;"
            End If

      Next
      If i_CurrentPage <> i_TotalPages Then
      ncount=ncount+1
                  strOutput = strOutput & "&nbsp;&nbsp;<a href=""" & strThisPage _
                  & "?StartingRecord=" & newstartrecord & "&ispageset=true&ncnt="& ncount &""">Next</a>&nbsp;&nbsp;"
      End If
      GetPagingHTML = strOutput
      end if
  End Function

'create the navigation links for paging
  Public Function GetPagingHTML1()
  response.write(request("ncnt"))
      Dim strOutput
      Dim strThisPage
      Dim pageset,newstartrecord
      pageset=3
      Dim i,nextpageset,pagesetconstraint
      strThisPage = Request.ServerVariables("SCRIPT_NAME")
      strOutput = "Result Page:"

      dim strec
       If i_CurrentPage > pageset then
       strec = (pageset-1) * i_RecordsPerPage + 1
      strOutput = strOutput & "&nbsp;&nbsp;<a href=""" & strThisPage _
      & "?StartingRecord=" & strec &""">Previous</a>&nbsp;&nbsp;" '((i_CurrentPage - 1)* i_RecordsPerPage) - i_RecordsPerPage + 1 _

      End If
      'If i_CurrentPage <> 1 Then
      '      strOutput = strOutput & "&nbsp;&nbsp;<a href=""" & strThisPage _
      '            & "?StartingRecord=" & ((i_CurrentPage - 1)* i_RecordsPerPage) - i_RecordsPerPage + 1 _
      '            & """>Previous</a>&nbsp;&nbsp;"
      'End If
      nextpageset = i_TotalPages mod pageset


      if nextpageset < pageset then
            pagesetconstraint = nextpageset + pageset

      end if
      if nextpageset > pageset then
            pagesetconstraint = pageset + pageset
      end if
      if nextpageset = 0 then
            nextpageset = pageset + pageset
            pagesetconstraint = nextpageset
      end if

      newstartrecord = i_RecordsPerPage * nextpageset + 1
      'response.write(i_TotalPages &"--" & nextpageset &"--" &pagesetconstraint)
      response.write("--"&ncount)
      if request("ncnt") <> "" then
            'if session("pagecnt") = "" then
            '      session("pagecnt") = request("ncnt")
            'else
            '      session("pagecnt") = cint(cstr(session("pagecnt"))) + cint(request("ncnt"))
            'end if
            pageset = pageset * cint(request("ncnt"))
            pagesetconstraint = pageset/cint(request("ncnt")) + pageset
            ncount=cint(request("ncnt")) +1
      end if

      For i = pageset+1 To pagesetconstraint

            If i <> i_CurrentPage Then
                        strOutput = strOutput & "&nbsp;&nbsp;<a href=""" & strThisPage _
                        & "?StartingRecord=" & (i * i_RecordsPerPage) - i_RecordsPerPage + 1 _
                        & "&ispageset=true"">" & i & "</a>&nbsp;&nbsp;"
            Else
                  strOutput = strOutput & "&nbsp;&nbsp;<b>" & i & "</b>&nbsp;&nbsp;"
            End If

            'newstartrecord=(i * i_RecordsPerPage) - i_RecordsPerPage + 1
            'response.write(newstartrecord & "-")
      Next
      'If i_CurrentPage <> i_TotalPages Then
      If i_TotalPages > pagesetconstraint Then
      ispageset = true

            strOutput = strOutput & "&nbsp;&nbsp;<a href=""" & strThisPage _
                  & "?StartingRecord=" & newstartrecord & "&ispageset=true&ncnt="& ncount &""">Next</a>&nbsp;&nbsp;"
      End If
      GetPagingHTML1= strOutput
  End Function

 

by: CleanupPingPosted on 2003-10-17 at 23:56:26ID: 9575724

yogman:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations!  No comment means you don't care.

 

by: YZlatPosted on 2004-06-03 at 12:31:43ID: 11226357

No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: ASPGuru

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

YZlat
EE Cleanup Volunteer

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...