Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 3rd, 2004, 09:41 AM
Authorized User
 
Join Date: Dec 2003
Location: , , .
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default Recordset Pagination (ASP Access)

Howdy, and thanks in advance for your help!

I'm not sure if what I'm trying to accomplish is called pagination, but what I'd like to do is to be able to break large recordsets up into pages that can be viewed in portions, so if I have a recordset of 124 records, my page would display 10 at a time, with "Next" and "Previous" buttons to page through the recordset...

I'm sure that there must be a good tutorial on the subject, and if you know of one, I'd love it if you can point me in the right direction! Or, if the solution is simple, here's more on what I'm doing:

I have successfully connected to my database, and have successful queries, but am not sure how to accomplish the above... I've included below, the essence of the .asp page that I'm trying to get working...

Thank You!!!

Darin

Code:



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
    <title>Recordsets</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link rel="STYLESHEET" type="text/css" href="default.css">

</head>

<body bgcolor="#FFFFFF" leftmargin="0" rightmargin="0" bottommargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="preloadImages();">

<table width="497" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td width="497" background="images/content_bg.gif" valign="top">
<%
    Dim vbQuote, strSelectSQL, strDetailLink
    vbQuote = Chr(34)

    strSelectSQL = "SELECT StockNum, Type, Auxiliary1, Special, Image1 FROM INV WHERE Type = 'Whatever' ORDER BY Auxiliary1 ASC"

    Set objRS = Server.CreateObject("ADODB.Recordset")
    objRS.Open strSelectSQL, strConnect, adOpenForwardOnly, adLockReadOnly, adCmdText
%>
            <table width="497" border="0" cellpadding="5" cellspacing="0">
                <tr>
                    <td width="487" valign="top" colspan="2" background="images/bg_blue_steel.gif">
                        <span class="contentheaderwhite"><%=objRS.Fields("NewOrUsed")%>&nbsp;<%=objRS.Fields("Type")%></span></td>                                
                </tr>
            </table>
            <table width="497" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="487" valign="top"><img src="images/blank.gif" height="18"></td>
                </tr>
            </table>
<!-- I'm thinking that a DoWhile or something like that would go here, so that if the recordset
     Had like 124 records, then the below section would be output for each record.  But the page
     would only show 10 records at a time, and a user could click "Next" etc. - is this called
     pagination? -->
            <table width="497" border="0" cellpadding="5" cellspacing="0">
                <tr>
                    <td width="100" valign="top" background="images/bg_lines_light_blue.gif">
<%
    If objRS.Fields("Image1") <> "" Then
        Response.Write "<IMG SRC=""" & objRS.Fields("Image1") & """ WIDTH=""98"" VSPACE=""5"" HSPACE=""5"" BORDER=""1"">"
    Else
        Response.Write "<IMG SRC=""images/norvimgsmall.gif"" WIDTH=""98"" VSPACE=""5"" HSPACE=""5"" BORDER=""1"">"
    End If
%>
                    </td>
                    <td width="350" valign="top" background="images/bg_lines_light_blue.gif">
                        <table width="350" border="0" cellpadding="5" cellspacing="0">
                            <tr>
                                <td width="50%" valign="top" class="contenttext">
                                    <span class="listheader"><%=objRS.Fields("Year")%>&nbsp;<%=objRS.Fields("Manufacturer")%>&nbsp;<%=objRS.Fields("Brand")%>&nbsp;<%=objRS.Fields("Model")%></span></td>
                                <td width="50%" valign="top" align="right" background="images/bg_line_light_blue.gif">
                                    <a href="rv_detail.asp?ID=<%=objRS.Fields("StockNum")%>"><img src="images/clickherefordetails.gif" width="129" height="16" border="0" align="right"></a>
                                    </td>
                            </tr>    
                            <tr>
                                <td width="50%" valign="top" class="contenttext">
                                    <span class="detailtextbold">Length:</span> <%=objRS.Fields("Length")%><BR>
                                    <img src="images/blank.gif" width="165" height="3" border="0" vspace="0" hspace="0"><BR>
                                    <span class="detailtextbold">Location:</span><%=objRS.Fields("City")%><BR>
                                    <img src="images/blank.gif" width="165" height="3" border="0" vspace="0" hspace="0"><BR>
                                    <span class="detailtextbold">Stock Number:</span><%=objRS.Fields("StockNum")%></td>
                                <td width="50%" valign="top" class="contenttext">
                                    <span class="detailtextbold">Price:</span> <span class="pricesmall"><%=objRS.Fields("Price")%></span><BR>
                                    <img src="images/blank.gif" width="165" height="3" border="0" vspace="0" hspace="0"><BR>
                                    <span class="detailtextbold">For More Information:</span><BR>(800) 555-2111
<%
    If objRS.Fields("Special") = "Yes" Then
            Response.Write "<BR><BR><img src=""images/internetspecialicon.gif"" border=""0"" vspace=""0"">"
    End If
%>
                                    </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
            <table width="497" border="0" cellpadding="0" cellspacing="0>
                <tr>
                    <td width="487" valign="top"><img src="images/blank.gif" height="18"></td>
                </tr>
            </table>

<%
    objRS.Close
    Set objRS=Nothing
%>                
        </td>
    </tr>
</table>

</body>
</html>
Reply With Quote
  #2 (permalink)  
Old May 3rd, 2004, 11:11 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

I've done something similar to this in the past. I used two querystring variables to hold:

- the total number of results per page
- the first record to display

You got to use some math to determine the last record to display and such, and for creating the links for the next and previous buttons. After that, you can use the Recordset.Move method to move to the first record. You would then check to see if the record doesn't exceed the limit for the page and that an end of file doesn't exist every time you move to the next record.

Hope this helps,

Brian Mains
Reply With Quote
  #3 (permalink)  
Old May 3rd, 2004, 12:43 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try this link. Hope this helps

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

Quote:
quote:Originally posted by darinsee
 Howdy, and thanks in advance for your help!

I'm not sure if what I'm trying to accomplish is called pagination, but what I'd like to do is to be able to break large recordsets up into pages that can be viewed in portions, so if I have a recordset of 124 records, my page would display 10 at a time, with "Next" and "Previous" buttons to page through the recordset...

I'm sure that there must be a good tutorial on the subject, and if you know of one, I'd love it if you can point me in the right direction! Or, if the solution is simple, here's more on what I'm doing:

I have successfully connected to my database, and have successful queries, but am not sure how to accomplish the above... I've included below, the essence of the .asp page that I'm trying to get working...

Thank You!!!

Darin

Code:



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
    <title>Recordsets</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link rel="STYLESHEET" type="text/css" href="default.css">

</head>

<body bgcolor="#FFFFFF" leftmargin="0" rightmargin="0" bottommargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="preloadImages();">

<table width="497" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td width="497" background="images/content_bg.gif" valign="top">
<%
    Dim vbQuote, strSelectSQL, strDetailLink
    vbQuote = Chr(34)

    strSelectSQL = "SELECT StockNum, Type, Auxiliary1, Special, Image1 FROM INV WHERE Type = 'Whatever' ORDER BY Auxiliary1 ASC"

    Set objRS = Server.CreateObject("ADODB.Recordset")
    objRS.Open strSelectSQL, strConnect, adOpenForwardOnly, adLockReadOnly, adCmdText
%>
            <table width="497" border="0" cellpadding="5" cellspacing="0">
                <tr>
                    <td width="487" valign="top" colspan="2" background="images/bg_blue_steel.gif">
                        <span class="contentheaderwhite"><%=objRS.Fields("NewOrUsed")%>&nbsp;<%=objRS.Fields("Type")%></span></td>                                
                </tr>
            </table>
            <table width="497" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="487" valign="top"><img src="images/blank.gif" height="18"></td>
                </tr>
            </table>
<!-- I'm thinking that a DoWhile or something like that would go here, so that if the recordset
     Had like 124 records, then the below section would be output for each record.  But the page
     would only show 10 records at a time, and a user could click "Next" etc. - is this called
     pagination? -->
            <table width="497" border="0" cellpadding="5" cellspacing="0">
                <tr>
                    <td width="100" valign="top" background="images/bg_lines_light_blue.gif">
<%
    If objRS.Fields("Image1") <> "" Then
        Response.Write "<IMG SRC=""" & objRS.Fields("Image1") & """ WIDTH=""98"" VSPACE=""5"" HSPACE=""5"" BORDER=""1"">"
    Else
        Response.Write "<IMG SRC=""images/norvimgsmall.gif"" WIDTH=""98"" VSPACE=""5"" HSPACE=""5"" BORDER=""1"">"
    End If
%>
                    </td>
                    <td width="350" valign="top" background="images/bg_lines_light_blue.gif">
                        <table width="350" border="0" cellpadding="5" cellspacing="0">
                            <tr>
                                <td width="50%" valign="top" class="contenttext">
                                    <span class="listheader"><%=objRS.Fields("Year")%>&nbsp;<%=objRS.Fields("Manufacturer")%>&nbsp;<%=objRS.Fields("Brand")%>&nbsp;<%=objRS.Fields("Model")%></span></td>
                                <td width="50%" valign="top" align="right" background="images/bg_line_light_blue.gif">
                                    <a href="rv_detail.asp?ID=<%=objRS.Fields("StockNum")%>"><img src="images/clickherefordetails.gif" width="129" height="16" border="0" align="right"></a>
                                    </td>
                            </tr>    
                            <tr>
                                <td width="50%" valign="top" class="contenttext">
                                    <span class="detailtextbold">Length:</span> <%=objRS.Fields("Length")%><BR>
                                    <img src="images/blank.gif" width="165" height="3" border="0" vspace="0" hspace="0"><BR>
                                    <span class="detailtextbold">Location:</span><%=objRS.Fields("City")%><BR>
                                    <img src="images/blank.gif" width="165" height="3" border="0" vspace="0" hspace="0"><BR>
                                    <span class="detailtextbold">Stock Number:</span><%=objRS.Fields("StockNum")%></td>
                                <td width="50%" valign="top" class="contenttext">
                                    <span class="detailtextbold">Price:</span> <span class="pricesmall"><%=objRS.Fields("Price")%></span><BR>
                                    <img src="images/blank.gif" width="165" height="3" border="0" vspace="0" hspace="0"><BR>
                                    <span class="detailtextbold">For More Information:</span><BR>(800) 555-2111
<%
    If objRS.Fields("Special") = "Yes" Then
            Response.Write "<BR><BR><img src=""images/internetspecialicon.gif"" border=""0"" vspace=""0"">"
    End If
%>
                                    </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
            <table width="497" border="0" cellpadding="0" cellspacing="0>
                <tr>
                    <td width="487" valign="top"><img src="images/blank.gif" height="18"></td>
                </tr>
            </table>

<%
    objRS.Close
    Set objRS=Nothing
%>                
        </td>
    </tr>
</table>

</body>
</html>
Reply With Quote
  #4 (permalink)  
Old May 3rd, 2004, 03:26 PM
Authorized User
 
Join Date: Dec 2003
Location: , , .
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the input guys - I noticed that www.asp101.com has a few different tutorials on the matter that made the issue seem pretty simple...

Thank You!! :D
Reply With Quote
  #5 (permalink)  
Old May 7th, 2004, 11:05 AM
Authorized User
 
Join Date: Dec 2003
Location: , , .
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

p.s. - www.aspin.com also had some VERY easy tutorials that made it a breeze, including crafty navigation of the paged recordset...

Thanks!!

Darin

Reply With Quote
  #6 (permalink)  
Old May 14th, 2004, 10:51 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I used the same code from ASP101.com but when I retreive my data I can only get my first page when I click on NEXT my records are empty but it tells me I 129 records???

Anybody seen this before?

Dan

Reply With Quote
  #7 (permalink)  
Old May 14th, 2004, 10:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

You must be missing something for sure.

-Vijay G
Reply With Quote
  #8 (permalink)  
Old September 24th, 2004, 03:52 AM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

pls get me the code for pagination in ASP
Bino
Reply With Quote
  #9 (permalink)  
Old September 24th, 2004, 07:45 AM
Friend of Wrox
 
Join Date: Sep 2004
Location: Hyderabad, Andhra Pradesh, India.
Posts: 104
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sureshbabu Send a message via Yahoo to sureshbabu
Default

Hi,
   The following code will help you.
------------------------------------
<%@ Language=VBScript %>

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<%
dim objRs,objConn,strSql
set objRS =server.CreateObject("ADODB.Recordset")
set objConn = server.CreateObject("ADODB.Connection")
objConn.ConnectionString ="Provider=Sqloledb.1;Dsn=Sureshbabu;Database=samp le;uid=sa;pwd=007"
objRs.CursorLocation = 3
objConn.Open
strSql ="select * from emp"
objRs.Open strSql,objConn,3,2
objRs.PageSize =2
dim strColor,intCount
intCount = 1


%>
<form name=form1 action="paging.asp?path=excel" method=post>
<table border=1 width=100%>
    <tr>
        <TD><b>EmpNo</b></td><TD><b>EName</b></td><TD><b>Salary</b></td>
    </tr>
<%
dim lngPage
lngPage = cint(Request.QueryString("Page"))
if lngPage < 1 then
    lngPage = 1
end if
objRs.AbsolutePage = lngPage
while objRs.AbsolutePage = lngPage
if intCount mod 2 = 0 then
    strColor= "eeeeee"
else
    strColor="ffffff"
end if
%>
    <tr bgcolor=<%=strColor%>>
        <TD><b><%=objRs(0)%></b></td><TD><b><%=objRs(1)%></b></td><TD><b><%=objRs(2)%></b></td>
    </tr>
<%objRs.MoveNext
intCount = intCount + 1
wend%>

<%
lngPage = cint(Request.QueryString("Page"))
    if lngpage < 1 then
        lngpage =1
    end if
objRs.AbsolutePage = lngPage
%>
    <tr>
        <%if objRs.AbsolutePage = objRs.PageCount then %>
        <td colspan=3 align=right>
        No Of Records : <%=objRs.AbsolutePosition%> - <%=objRs.RecordCount%>&nbsp;&nbsp; Of&nbsp;&nbsp; <%=objRs.RecordCount %>
        </td>
        <%else%>
        <td colspan=3 align=right>
        No Of Records : <%=objRs.AbsolutePosition%> - <%= objRs.PageSize * objRs.AbsolutePage %>&nbsp;&nbsp; Of &nbsp;&nbsp;<%=objRs.RecordCount %>
        </td>
        <%end if%>
    </tr>
<tr>
    <td colspan=3 align=left>
        <%if objRs.AbsolutePage <> 1 then %>
            <a href=paging.asp?Page=1>First</a>|
        <%end if%>
        <%if objRs.AbsolutePage <> 1 and objRs.AbsolutePage <> 2 then %>
        <a href=paging.asp?Page=<%=objRs.AbsolutePage - 1%>>Previous</a>|
        <%end if%>
        <%if objRs.AbsolutePage <> objRs.PageCount and objRs.AbsolutePage <> objRs.PageCount - 1 then %>
        <a href=paging.asp?Page=<%=objRs.AbsolutePage + 1%>>Next</a>|
        <%end if%>
        <%if objRs.AbsolutePage <> objRs.PageCount then%>
        <a href=paging.asp?Page=<%=objRs.PageCount %>>last</a>|
        <%end if%>

    </td>
</tr>

</table>
</form>
</BODY>
</HTML>
---------------------------------------------
Thanks
Suresh

Reply With Quote
  #10 (permalink)  
Old September 24th, 2004, 05:30 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Bino,

Didn't you find the code from the links that were posted above useful?

Cheers!

_________________________
- Vijay G
Strive for Perfection
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
asp/Access recordset navigation query murshed Classic ASP Databases 1 April 10th, 2008 01:43 PM
How to access a recordset without connection? JelfMaria VB How-To 9 June 30th, 2005 12:01 AM
Pagination in asp nkramanmca Classic ASP Components 1 February 4th, 2005 06:19 AM
Urgent: Pagination in ASP using arrays ,code reqd. jyoti_khera BOOK: Beginning ASP 3.0 1 October 19th, 2004 12:25 PM
Recordset date insert in access kev_79 Access ASP 3 June 5th, 2003 12:49 PM



All times are GMT -4. The time now is 07:55 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.