Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: navbuttons


Message #1 by "Mark" <marks20101@c...> on Thu, 2 May 2002 14:31:56
Hello, I was wondering how to go about quering 5 rows of data per page and 
have a NavButton to send me to the next or prev page of 5 rows. you can 
keep the code inshort, I have an understanding of programming but new to 
asp Thanks
Message #2 by Joe Ingle <Joe@k...> on Thu, 2 May 2002 14:47:32 +0100
Hi Mark

This will need tweaking to your exact spec.

<!--#include file = "ConnString.asp"--> 
<%
Dim mySQL
Dim intPageCount		
Dim intRecordCount		
Dim intPage			
Dim intRecord			
Dim intStart			
Dim intFinish				

if request.querystring("NAV") = "" then
intPage = 1	
else
intPage = request.querystring("NAV")
end if		

if replace(request.form("txtKeySearch"),"'","") <> "" then
txtKeySearch = replace(request.form("txtKeySearch"),"'","")
else
txtKeySearch = request.querystring("txtKeySearch")
end if

mySQL = "SELECT * FROM YOURTABLE WHERE YOURSEARCHCOLUMN = '"&txtKeySearch&"'
" 

set ObjRS = server.createobject("adodb.recordset")

ObjRS.cursorlocation 	= 3	
ObjRS.cursortype 		= 3		
ObjRS.activeconnection 	= ObjConn

ObjRS.open mySQL


ObjRS.pagesize 		= 5	
ObjRS.cachesize 		= ObjRS.pagesize
intpagecount 		= ObjRS.pagecount 
intrecordcount 		= ObjRS.recordcount 

if cint(intpage) > cint(intpagecount) then intpage = intpagecount
if cint(intpage) <= 0 then intpage = 1

if intrecordcount > 0 then
ObjRS.absolutepage = intpage
intstart = ObjRS.absoluteposition
if cint(intpage) = cint(intpagecount) then
intfinish = intrecordcount
else
intfinish = intstart + (ObjRS.pagesize - 1)
end if
end if
%>
<HTML> 
<HEAD> 
<TITLE></TITLE> 
</HEAD> 

<BODY> 
<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" HEIGHT="100%"
BORDER="0"> 
<TR> 
<TD ALIGN="LEFT" VALIGN="TOP">
<!--Page Contents-->
<%
if intRecordCount > 0 then
response.write("<P>You are now viewing records <B>"&intStart&"</B> to
<B>"&intFinish&"</B> of "&intRecordCount&"</P>")& vbCrLf
else
response.write("<P>Sorry, your search returned no records.<BR>")& vbCrLf
end if
%>
<%
if not ObjRS.eof then
for intRecord = 1 to ObjRS.pagesize
response.write("<TABLE CELLPADDING=""0"" CELLSPACING=""0"" BORDER=""0""
WIDTH=""100%""> ")& vbCrLf
response.write("<TR> ")& vbCrLf
response.write("<TD ALIGN=""LEFT"" VALIGN=""MIDDLE"">")
response.write("<P>"&ObjRS("COLUMN-ONE")&"</P>")
response.write("<P>"&ObjRS("COLUMN-TWO")&"</P>")
response.write("</TD></TR> ")& vbCrLf
response.write("<TR> ")& vbCrLf
response.write("<TD ALIGN=""LEFT"" VALIGN=""MIDDLE"" HEIGHT=""5""></TD></TR>
")& vbCrLf
response.write("</TABLE>")& vbCrLf
end if
ObjRS.movenext
if ObjRS.eof then exit for
next
end if
%> 
<!--End Page Contents-->
</TD> 
</TR> 
<TR> 
<TD ALIGN="LEFT" VALIGN="BOTTOM">
<HR>
<%
if cint(intpage) > 1 then
%>
<A HREF="SearchPage.asp?NAV=<%=intpage -
1%>&txtKeySearch=<%=txtKeySearch%>">Previous</A>
<%
end if
%>
<%
if cint(intpage) < cint(intpagecount) then
%>
<A HREF="SearchPage.asp?NAV=<%=intpage +
1%>&txtKeySearch=<%=txtKeySearch%>">Next</A>
<%
end if
%>	
</TD> 
</TR> 
</TABLE> 

</BODY>
</HTML>
<%
ObjRS.close
set ObjRS = nothing
%>
<!--#include file = "ConnStringClose.asp"--> 

Hope this helps

Joe

-----Original Message-----
From: Mark [mailto:marks20101@c...]
Sent: Thursday, May 02, 2002 3:32 PM
To: ASP Web HowTo
Subject: [asp_web_howto] navbuttons


Hello, I was wondering how to go about quering 5 rows of data per page and 
have a NavButton to send me to the next or prev page of 5 rows. you can 
keep the code inshort, I have an understanding of programming but new to 
asp Thanks

---

Improve your web design skills with these new books from Glasshaus.

Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
r-20
Message #3 by "Drew, Ron" <RDrew@B...> on Thu, 2 May 2002 10:21:07 -0400
http://www.asp101.com/samples/viewasp.asp?file=3Ddb%5Fpaging%2Easp

-----Original Message-----
From: Mark [mailto:marks20101@c...]
Sent: Thursday, May 02, 2002 10:32 AM
To: ASP Web HowTo
Subject: [asp_web_howto] navbuttons


Hello, I was wondering how to go about quering 5 rows of data per page
and
have a NavButton to send me to the next or prev page of 5 rows. you can
keep the code inshort, I have an understanding of programming but new to

asp Thanks

---

Improve your web design skills with these new books from Glasshaus.

Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=3Dnosim/theprogramm
e
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=3Dnosim/theprogramm
e
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=3Dnosim/theprogramm
e
r-20
Message #4 by "phil griffiths" <pgtips@m...> on Fri, 3 May 2002 14:05:23
Its also possible to do in client-side javascript.  Advantage of doing it 
this way is you don't have to go back to server for next page, so the 
paging response is instant.  Disadvantage is that you have to send all 
data from the server up-front so the page takes longer to load.

How you do it depends on what browsers you need to support.  2 ways I've 
done this before are:
1. write all data to js array, then write client-side code to build the 
page from selected rows of the array.  This is messy but it works for I4 
and NS4 (although there was a lot of fiddling around to get NS to display 
correctly during paging).
2. write each page into a separate HTML block object (e.g. table or div) 
and use js to show/hide each page.  This is much cleaner but I haven't 
tried it on NS (it was for intranet so only IE4+ was needed).

I can give you more details if you're interested.

HTH
Phil
> Hi Mark

This will need tweaking to your exact spec.

<!--#include file = "ConnString.asp"--> 
<%
Dim mySQL
...
ObjRS.close
set ObjRS = nothing
%>
<!--#include file = "ConnStringClose.asp"--> 

Hope this helps

Joe

-----Original Message-----
From: Mark [mailto:marks20101@c...]
Sent: Thursday, May 02, 2002 3:32 PM
To: ASP Web HowTo
Subject: [asp_web_howto] navbuttons


Hello, I was wondering how to go about quering 5 rows of data per page and 
have a NavButton to send me to the next or prev page of 5 rows. you can 
keep the code inshort, I have an understanding of programming but new to 
asp Thanks

  Return to Index