Paging Recordsets with ASP JavaScript
Hi there,
Here the code for Paging RecordSets with ASP JavaScript, I Hope this will be useful for you and others :)
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!--#include file="adojavas.inc" -->
<%
var thisPage = new String(Request.QueryString("thisPage"))
var isthisPage = (thisPage != "" && String(Request.QueryString("thisPage")) != "undefined");
if (isthisPage == false)
{
thisPage = 1;
}
if (isthisPage == true)
{
thisPage = thisPage;
}
if ((thisPage!=""))
{
thisPage = thisPage;
}
else
{
thisPage = 1;
}
var conn=Server.CreateObject("ADODB.Connection");
conn.Provider="Microsoft.Jet.OLEDB.4.0";
conn.Open(Server.MapPath("/db/db.mdb"));
var rs=Server.CreateObject("ADODB.recordset");
sql="SELECT * FROM users";
rs.CursorLocation = adUseClient;
rs.CursorType = adOpenStatic;
rs.LockType = adLockBatchOptimistic;
rs.Open (sql,conn);
rs.PageSize=5;
rs.AbsolutePage = thisPage;
var rowCount = 0;
%>
<!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" />
<!--Developed By Rahul Dev Katarey, Copyright © http://www.katarey.com-->
<title>Paging Recordsets with ASP JavaScript</title>
</head>
<body>
<table border="1" cellpadding="2" cellspacing="2" bordercolor="#CCCCCC">
<tr>
<th width="50" valign="top">ID</th>
<th width="150" valign="top">Name</th>
</tr>
<%
do
{
%>
<tr>
<td width="50" valign="top"><%=(rs.Fields.Item("id").Value)%></td>
<td width="150" valign="top"><%=(rs.Fields.Item("UName").Value)%></td>
</tr>
<%
rowCount = rowCount + 1;
rs.MoveNext
}
while (!rs.EOF && rowCount < rs.PageSize)
%>
</table>
<table border="0" cellpadding="3" cellspacing="3" style="border:1px solid #cccccc;">
<tr>
<%
for (i=1;i<=rs.PageCount;i++)
{
%>
<td valign="middle"><a href="?thisPage=<%=i%>" class='navLinks'><%=i%></a></td>
<% } %>
</tr>
</table>
<%
rs.Close
conn.Close
%>
</body>
</html>
Best Regards,
Rahul Dev Katarey