Library code snippets
Improvements to the "Paginate a recordset" Post by James Crowley
Search Results indexing across multiple pages
Hi Guys
This code i really simple but you have to know how request.querystrings work.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%' you need to include your database mappath location%>
<!--#Include file="cn.asp"-->
<%
'create a recordset object
Set rItems = Server.CreateObject("ADODB.Recordset")
'set the cursor location and type
rItems.CursorLocation = 3' adUseClient
rItems.CursorType = 3 'adOpenStatic
'number of rows to cache at a time. Should be set to the same as PageSize
rItems.CacheSize = 10
'number of items to display per 'page'
rItems.PageSize = 10
dim rs
dim cn
set cn = Server.CreateObject("Adodb.Connection")
cn.Open conn
sqlstring = "Select * From staffnames" 'change this to suit your db
rItems.open sqlstring, cn
'check if empty
If rItems.EOF Then
'no rows
Else
'set current page
if request.QueryString("page") <> "" then ' if page= nothing this you are on the first page without this if statement you would get an error like Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
rItems.AbsolutePage = Request.QueryString("page")
end if
'get the total number of records
nItemCount = rItems.RecordCount
'get the number of pages
nPageCount = rItems.PageCount
'loop through an display the items in the recordset
Do While Not rItems.EOF and nItem < rItems.PageSize
'displays records
response.write rItems.fields("Name")
%><br /><%
'do something
rItems.MoveNext 'move to the next record
nItem=nItem+1 'increment count
Loop
End If
'close the recordset
rItems.Close
'and destroy the object...
Set rItems = Nothing
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<p> </p>
<p>
<%
' this loop works out the amount of pages needed and then writes them in html
dim i
i = 1
for i =1 to nPageCount%>
<a href="default2.asp?page=<%=i%>"><%=i%></a>
<%
next
%>
</p>
</body>
</html>
if you need help let me know.
Good luck!
Related articles
Related discussion
-
how to select multiple files at a time using Ctrl+select and upload the attachments in C# .Net 1.0?
by vasanta (0 replies)
-
Header and Footer in Web page print
by fhajaj (4 replies)
-
help me to get simple requirement
by Slicksim (1 replies)
-
Gridview -> Template Field -> Button
by antti.simonen (1 replies)
-
Classic ASP : Page expires
by chezhian_in05 (0 replies)
Related podcasts
-
ASP.NET Caching and Performance
Steve Smith, owner of ASP Alliance and Lake Quincy Media joins us today to teach us about some hidden gems in ASP.NET caching and performance. Steve’s expertise in this area comes from first-hand experience as Lake Quincy’s ad system serves over 60 requests per second and handles over 150 million...
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum) -
Microsoft Dynamics CRM Technical Consultant
in Netherlands (€50K-€90K per annum) -
Technical Support Engineer EMEA
in Reading (£50K-£50K per annum) -
Solutions Engineer
in Reading (£50K-£60K per annum)
This thread is for discussions of Improvements to the "Paginate a recordset" Post by James Crowley.