Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Paging records

Status
Not open for further replies.

Herminio

Technical User
May 10, 2002
189
PT
I want to prevent my pages to have the scroller bar, for that i need to show only 2 records on each page and display the links to navigate for the following pages, how do i do that?
 
Hi,

I found this on yesterday. I thought it might come in useful so I saved the code. The paging is set to display 5 records, but this can be changed. Please note this isn't my code.

Code:
    '**************************************
    ' Name: Database paging in ASP
    ' Description:I wanted to add paging cod
    '     e in my project.I've seen all other code
    '     s on the site but they are not at all wo
    '     rth for me. Now I've written a code whic
    '     h is very easy to understand and can be 
    '     used by any student or professional in t
    '     heir projects.
    ' By: Vivek Tanaji Kulthe
    '
    ' Returns:This program displays 5 record
    '     s at a time from any database. You can c
    '     hange no. of records per page by changin
    '     g the value of iPageSize variable
    '
    ' Assumes:This program assumes that you 
    '     have dsn = 'myDSN' or replace 'myDSN' wi
    '     th your existing DSN.
    '
    'This code is copyrighted and has    
    ' limited warranties.Please see [URL unfurl="true"]http://w[/URL]
    '     ww.Planet-Source-Code.com/xq/ASP/txtCode
    '     Id.8122/lngWId.4/qx/vb/scripts/ShowCode.
    '     htm    
    'for details.    
    '**************************************
    
    <% 
    Const iPageSize=5	'How many records To show
    Dim CPage		'Current Page No.
    Dim Cn		'Connection Object
    Dim Rs		'Recordset Object
    Dim TotPage		'Total No. of pages if iPageSize
                        'records are displayed per page.
    Dim i		'Counter
    CPage=Cint(Request.Form(&quot;CurrentPage&quot;))	'get CPage value from form's CurrentPage field
    Select Case Request.Form(&quot;Submit&quot;)
    	Case &quot;Previous&quot;						'if prev button pressed
    		CPage = Cint(CPage) - 1			'decrease current page
    	Case &quot;Next&quot;							'if next button pressed
    		CPage = Cint(CPage) + 1			'increase page count
    End Select
    Set	Cn=Server.CreateObject(&quot;ADODB.Connection&quot;)	'create connection
    	Cn.CursorLocation = 3
    	Cn.Open &quot;myDSN&quot;
    Set	Rs=Server.CreateObject(&quot;ADODB.Recordset&quot;)	'create recordset
    	Rs.Open &quot;Select * from studentmaster&quot;,Cn,2,2
    	Rs.PageSize=iPageSize
    if CPage=0 Then CPage=1						'initially make current page = first page
    if Not(Rs.EOF) Then Rs.AbsolutePage=CPage	'specifies that current record resides In CPage
    TotPage=Rs.PageCount						'stores total no. of pages
    %>
    <HTML>
    <BODY>
    <H2>Database paging example</H2>
    by Vivek Kulthe (<A href = &quot;mailto:vivekkulthe@yahoo.com&quot;>vivekkulthe@yahoo.com</A>)<P>						
    <TABLE BORDER = 1>
    <%
    Response.Write(&quot;<TR><TD><B>&quot; & Rs.Fields(1).Name & &quot;</TD><TD><B>&quot; & Rs.Fields(2).Name	& &quot;</TD></TR>&quot;)	'display title For table
    %>
    <% 
    For i=1 To Rs.PageSize
    	Response.Write (&quot;<TR><TD>&quot; & Rs(1) & &quot;</TD><TD>&quot; & Rs(2) & &quot;</TD><TR>&quot;)	'display table records upto PageSize 
    	Rs.MoveNext
    	if Rs.EOF Then Exit For
    Next
    'close all connections and recordsets
    Rs.Close			
    Cn.Close
    Set Rs = Nothing
    Set Cn = Nothing
    %>
    </TABLE>
    <BR>
    Page <%=CPage %> of <%=TotPage %><P>					
    <!--'store current page value In hidden Type and display next-prev buttons-->
    <FORM Action=&quot;<%=Request.ServerVariables(&quot;SCRIPT_NAME&quot;) %>&quot; Method=POST>
    	
    		<INPUT Type=Hidden name=&quot;CurrentPage&quot; Value=&quot;<%=CPage%>&quot; >
    	<% if CPage > 1 Then %>
    		<INPUT type=Submit Name=&quot;Submit&quot; Value=&quot;Previous&quot;>
    	<% End if%> 
    	<% if CPage <> TotPage Then %>
    		<INPUT type=Submit Name=&quot;Submit&quot; Value=&quot;Next&quot;>
    	<% End if %> 
    </FORM>
    </BODY>
    </HTML>

Hope you find it useful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top