 |
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

May 3rd, 2004, 09:41 AM
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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")%> <%=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")%> <%=objRS.Fields("Manufacturer")%> <%=objRS.Fields("Brand")%> <%=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>
|

May 3rd, 2004, 11:11 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|

May 3rd, 2004, 12:43 PM
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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")%> <%=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")%> <%=objRS.Fields("Manufacturer")%> <%=objRS.Fields("Brand")%> <%=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>
|
|

May 3rd, 2004, 03:26 PM
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

May 7th, 2004, 11:05 AM
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

May 14th, 2004, 10:51 AM
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

May 14th, 2004, 10:57 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
You must be missing something for sure.
-Vijay G
|

September 24th, 2004, 03:52 AM
|
Registered User
|
|
Join Date: Sep 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
pls get me the code for pagination in ASP
Bino
|

September 24th, 2004, 07:45 AM
|
Friend of Wrox
|
|
Join Date: Sep 2004
Posts: 104
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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%> Of <%=objRs.RecordCount %>
</td>
<%else%>
<td colspan=3 align=right>
No Of Records : <%=objRs.AbsolutePosition%> - <%= objRs.PageSize * objRs.AbsolutePage %> Of <%=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
|

September 24th, 2004, 05:30 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Bino,
Didn't you find the code from the links that were posted above useful?
Cheers!
_________________________
- Vijay G
Strive for Perfection
|
|
 |