Active Server Pages Programming (ASP)/Paging in asp
Expert: Srini Nagarajan - 10/19/2011
Questionhello,
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..
AnswerHi 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
%>