HOW TO CREATE PAGING IN CLASSIC ASP , paging code in asp program , how to display a report page by page
Step 1 Check whether "inetpub/wwwroot" folder is there in C:/.
If it is not there, then may be IIS is not installed in your PC. You must
install IIS to run ASP program. Once IIS installed, the folder "inetpub/wwwroot"
will be automatically created.
Step 2: Under inetpub/wwwroot create a folder "EMP"
Step 3: Under the Emp folder create an mdb file with name emp.mdb
Step 4: Under Emp.mdb create a table with table name "emp"
Step 5. Under emp table create the following fields
StaffNumber......Number
EmpName ....text
Post.......text
step 6. Enter some sample data into the table as shown here:
StaffNumber |
EmpName |
Post |
1 |
Ram |
Manager |
2 |
Ravi |
Accountant |
3 |
Peter |
Clerk |
4 |
james |
Peon |
step 7. Create an asp file using notepad with file name "paging.asp"
with the following code
<%
'tutorial on pagination or paging in classic
asp programming
'page number should be passed to this page from the previous page.
'If page number is not passed, it will bet taken as 1.
%>
<html>
<head>
<title>Paging</title>
</head>
<body>
<%
set con=server.createobject("adodb.connection")
con.open "PROVIDER=Microsoft.jet.oledb.4.0;data Source=" &
Server.MapPath("emp.mdb") & ";"
sql="select * from emp order by empname"
%>
<%
set Rs=Server.CreateObject("ADODB.Recordset")
Rs.CursorLocation=3 ' this is important
%>
<%
'PART 1/3 OF PAGING CODE STARTS HERE
no_of_records_per_page=2
Rs.PageSize=no_of_records_per_page ' this decides no. of records per page
Rs.CacheSize=no_of_records_per_page ' this is not important
Rs.Open sql,con
If not Rs.eof then
If Len(Request("pagenum"))=0 Then
Rs.AbsolutePage=1
Else
If CInt(Request("pagenum"))<=Rs.PageCount Then
Rs.AbsolutePage=Request("Pagenum")
else
Rs.AbsolutePage=1
end If
End If
total_pages=Rs.PageCount
current_page=Rs.AbsolutePage
end If
'End of Part 1/3 of Paging
%>
<%If Rs.eof then
Response.write("No Records Present")
End If
%>
<%
If not Rs.eof then
%>
<%
' PART 2/3 OF PAGING STARTS HERE
total_columns_in_the_report=4
%>
<table width=52% height="91" border="1" align=center
cellpadding="0" cellspacing="0" class="ctms">
<tr>
<td colspan=<%=total_columns_in_the_report%> align="center">
<%
If total_pages > 1 then
response.write("Pages : ")
for k=1 to total_pages
If k=current_page then%>
<a style="background-color:#d0d0d0" href="#"><%=k%></a>
<%
else%>
<a style="background-color:#f0f0f0" href="paging.asp?post=11&pagenum=<%=k%>"><%=k%></a>
<%
end If
next
end If
%>
</td>
</tr>
<tr >
<th width="16%" class="ctms_very_small">
SNo
</th>
<th width="14%" class="ctms_very_small">
Staff No.
</th>
<th width="24%" class="ctms_very_small">
Employee Name
</th>
<th width="46%" class="ctms_very_small">
Post
</th>
</tr>
<%
' Part 3/3 of paging coding
i=1
j=(no_of_records_per_page * (current_page -1))+1
while not Rs.eof and i<=no_of_records_per_page
%>
<tr >
<td height=35>
<%=j%>
</td>
<td class="ctms_very_small">
<%=Rs("staffnumber")%>
</td>
<td class="ctms_very_small">
<%=Rs("empName")%>
</td>
<td class="ctms_very_small">
<%=Rs("Post")%>
</td>
</tr>
<%
i=i+1
j=j+1
Rs.movenext
wend
%>
</table>
<%
end If
%>
</body>
</html>
***************************************************
You will get the output as shown below. You can click and change the
page nos.
Pages :
1
2
|
SNo
|
Staff No.
|
Employee Name
|
Post
|
3
|
1
|
Ram
|
Manager
|
4
|
2
|
Ravi
|
Accountant
|
Code written by Kalaimathi for EnjoyStudy.blogspot.com
|
No comments:
Post a Comment