Active Server Pages Programming (ASP)/Paging in asp

Advertisement


Question
hello,
i am new to classic asp, help me out.
Suppose i have a asp page which navigates to another asp page which provides a long data like of 550 rows. i want to do paging there. how can i do that. i dont know how to do paging. i want on  page 100 rows on first and so on..

Answer
Hi Lisha,

You need to use ADO with paging option

Here is a sample code which gives you some idea


<!--#include file="includes/oConn.asp"-->
<!--#include file="includes/adovbs.inc"-->
<%
dim perPage, thisPage, i, rowCount
perPage = trim(request.QueryString("perPage"))
thisPage = Trim(Request("thisPage"))

if thisPage = "" then thisPage = 1
if perPage = "" then perPage = 10
dim theRS, theSQL
set theRS = server.CreateObject("ADODB.RecordSet")
theSQL = "SELECT * FROM videotable where show = 'yes' ORDER BY id DESC"

with theRS
       .CursorType = adOpenStatic
       .PageSize = perPage
       .Open portfolioSQL, MM_oConn_STRING
       .AbsolutePage = cINT(thisPage)
end with

theRS.Open theSQL, MM_oConn_STRING, adOpenStatic, adLockPessimistic , adCmdText

%>
<%
  rowCount = 0
 do while not theRS.eof and rowCount < theRS.pageSize
 %>
/*************************************
do your prints here
***********************************/
<%
 rowCount = rowCount+1
 theRS.movenext
 loop%>

<form name="form1" method="get" action="name-of-this-page.asp">
Records per page:
<input name="perPage" type="text" id="perPage" value="<%=perPage%>" size="2" maxlength="2">
     <input type="submit" name="Submit" value="Submit">
   </form>
<p>
<%
Response.Write "<br clear=all>Go to Page >"
   for i = 1 to portfolioRS.PageCount
   %>
<%=i%>
<% next %></p>


<%
theRS.close()
set theRS = nothing
%>

Active Server Pages Programming (ASP)

All Answers


Answers by Expert:


Ask Experts

Volunteer


Srini Nagarajan

Expertise

I can answer any kind of questions in ASP.NET, C#, VB.NET, SharePoint 2007, ASP, Coldfusion, Powerbuilder 7.00 / 8.00, JAVA servlets, MS SQL 2000 / MSSQL7, Sybase

Experience

Contact me if you need any custom development on ASP.NET, ASP, SharePoint 2007, Coldfusion, Powerbuilder.

©2012 About.com, a part of The New York Times Company. All rights reserved.