Tuesday, June 10, 2008

asp tutorial: Pagewise display of Records

ASP Code
How to display records
PAGEWISE

 

<%
Set Conn =Server.CreateObject("ADODB.Connection")
Conn.open="provider=MSDAORA;
data source=my_oracle_service;
user id=scott;password=tiger"
'Conn.open "PROVIDER=Microsoft.jet.oledb.4.0;
data Source=" &
Server.MapPath("mydb.mdb") & ";"
sql="select * from emp"
Set ObjRs=Server.CreateObject("ADODB.Recordset")
ObjRs.PageSize=50 ' 50 records in each page
ObjRs.CacheSzie=50
ObjRs.CursorLocation=3
' 3 means adUseClient
ObjRs.Open sql,conn,0,1
'0=adOpenForwardOnly,1=adLockReadOnly
If Not ObjRs.Eof Then
If Len(Request("pagenum"))=0 Then
'intially user request is empty
ObjRs.AbsolutePage=1
Else
If CInt(Request("pagenum"))<=ObjRs.PageCount Then
ObjRs.AbsolutePage=Request("Pagenum")
else
ObjRs.AbsolutePage=1
end if ' page is decided now
End if
total_pages=ObjRs.PageCount
current_page=ObjRs.AbsolutePage
End If
If ObjRs.eof Then
Response.write("No records present")
Else
%>
<table><tr>
<td colspan=7 align=center>
<%
''part 2/3
If total_pages > 1 then
Response.write("Pages : ")
For k=1 to total_pages
If k=current_page then%>
<a class="current_page" href="#"><%=k%></a>
<%else%>
<a href="abc.asp?id=<%=x%>&pagenum=<%=k%>">
<%=k%></a><%
End If
Next
End If
%>
</td></tr>

<tr >
<th>SNo</th>
<th>Emp Name</th>
</tr>
<%''PART 3/3
i=1
j=(50 * (current_page -1))+1
while not ObjRs.eof and i<=50
%>
<tr>
<td><%=j%></td>
<td><%=ObjRs("empname")%></td>
</tr>
<%
i=i+1
j=j+1
ObjRs.movenext
wend%>
</table>
<%
end if
%>


No comments:

 
Disclaimer and Copyright