ASP Code
  Home arrow ASP Code arrow Using the recordset object paging method t...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP CODE

Using the recordset object paging method to show a limited # of records per webpage
By: aspfree
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    1999-09-01

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


     

    Displaying a certain # of records on each webpage Paging

    Page 1-The page with the dropdown box.

    <html><head>
    <title>paging</title></head>
    <body>
    <form method="post" action="paging.asp" name="form1">
    <select name="d1">
    <option value="10">10</option>
    <option value="7">7</option>
    <option value="5">5</option>
    </select>
    <input type="submit" value="submit" name="b1">
    </form>
    </body>

    Page 2-The page that shows the records

    <%@ Language="VBScript"%>
    <!-- #INCLUDE FILE="./adovbs.Inc" -->
    <%
    ' I'm using a DSN-less connection.

    ConnString = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("paging.mdb")

    ' Declare variables
    Dim iPageSize        'How big our pages are
    Dim strPageCount        'The number of pages we get back
    Dim strPageCurrent    'The page we want to show
    Dim strSql            'SQL select to limit fields
    Dim conn    'The connection object
    Dim rs        'The recordset object
    Dim x                 'Standard looping var

    If request("d1") <> "" Then Session("d1") = request("d1")

    'Get parameters from the dropdown box on the previous page.
    ' You could easily just use the default of 10

    iPageSize = Session("d1")
    If Request("page") = "" Then
        strPageCurrent = 1
    Else
        strPageCurrent = CInt(Request("page"))
    End If

    'Create db connection and recordset objects
    'Open the connection string

    Set conn = Server.CreateObject("ADODB.Connection")
    Set rs = Server.CreateObject("ADODB.Recordset")
    conn.Open ConnString

    ' Set cursor location and pagesize
    rs.CursorLocation = adUseClient
    rs.PageSize = iPageSize

    'set sql statement to a local variable
    strSql = "SELECT * FROM table1 ORDER BY id;"

    ' Open Recordset object
    rs.Open strSql, conn, adOpenStatic, adLockReadOnly, adCmdText

    ' Get the count of the pages using the given page size
    strPageCount = rs.PageCount

    ' If the request page falls outside the range,
    ' give them the closest match (1 or max)

    If 1 > strPageCurrent Then strPageCurrent = 1
    If strPageCurrent > strPageCount Then strPageCurrent = strPageCount

    ' Move to the selected page
    rs.AbsolutePage = strPageCurrent

    ' Start output with a page x of n line
    Response.Write "<FONT SIZE=""+1"">Page <B>"
    Response.Write strPageCurrent
    Response.Write "</B> of <B>"
    Response.Write strPageCount
    Response.Write "</B></FONT><BR><BR>" & vbCrLf

    ' Continue with a title row in our table
    Response.Write "<TABLE BORDER=""1"">" & vbCrLf

    ' Show field names
    Response.Write vbTab & "<TR>" & vbCrLf
    For x = 1 To rs.Fields.Count
    Response.Write vbTab & vbTab & "<TD><B>"
    Response.Write rs.Fields(x - 1).Name
    Response.Write "<B></TD>" & vbCrLf
    Next
    Response.Write vbTab & "</TR>" & vbCrLf

    ' Loop through our records
    Do While rs.AbsolutePage = strPageCurrent And Not rs.EOF
        Response.Write vbTab & "<TR>" & vbCrLf
        For x = 1 To rs.Fields.Count
        Response.Write vbTab & vbTab & "<TD>"
        Response.Write rs.Fields(x - 1)
        Response.Write "</TD>" & vbCrLf
        Next
        Response.Write vbTab & "</TR>" & vbCrLf

    'Move to the next record!
        rs.MoveNext
    Loop

    'Closing html table tag
    Response.Write "</TABLE>" & vbCrLf

    ' Close all objects and clear from Memory
    rs.Close
    Set rs = Nothing
    conn.Close
    Set conn = Nothing

    'Show "previous" and "next"  links which navigate between pages
    If strPageCurrent <> 1 Then
        Response.Write "<A HREF=""./paging.asp?page="
        Response.Write strPageCurrent - 1
        Response.Write """>Previous Page</A>" & vbCrLf
        'Spacer - inside the if so we don't get it unless needed
        Response.Write "&nbsp;&nbsp;" & vbCrLf
    End If
    If strPageCurrent < strPageCount Then
        Response.Write "<A HREF=""./paging.asp?page="
        Response.Write strPageCurrent + 1
        Response.Write """>Next Page</A>" & vbCrLf
    End If

    %>

    <html><head>
    <title>paging demo</title></head>
    <body>
    </body>


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More ASP Code Articles
    More By aspfree

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Download the free Web Application Security eKit

    Discover how IBM Rational AppScan Standard Edition can help you detext vulnerabilities in your web applications in the Web Application Security eKit. IBM Rational AppScan is a leading suite of automated web application security solutions that scan and test for common Web application vulnerabilities. The new Web Application Security eKit provides you with valuable resources, including white papers, demos, and additional information on the benefits of testing your Web applications.
    FREE! Go There Now!


    NEW! IBM Rational AppScan Standard Edition V7.7

    Secure your Web applications with IBM Rational AppScan Standard Edition V7.7, previously known as Watchfire AppScan. This Web application security testing tool automates vulnerability assessments and scans and tests for common Web application vulnerabilities. Visit IBM developerWorks to download a free trial of IBM Rational AppScan Standard Edition V7.7.
    FREE! Go There Now!


    NEW! Maintaining QoS and Process Integrity in an SOA Environment

    This webcast outlines the best practices that must be instituted to gain the maximum benefit from SOA while maintaining high quality of service. Whether you are deploying new applications or managing and monitoring your existing infrastructure, learn how you can ensure high quality of services with SOA based solutions from IBM. All registrants who attend this live Web Seminar will receive complimentary access to a white paper titled “Maintaining QoS in an SOA Environment”.
    FREE! Go There Now!


    NEW! Rational Talks to You:Per Kroll on Rational Method Composer Plug-in customization

    Join this Rational Talks to You teleconference on December 11 at 1:00 pm ET to get tips on building your own plugins with Rational Method Composer. Get your questions answered!
    FREE! Go There Now!


    NEW! Section 508 of the U.S. Rehabilitation Act: Web accessibility compliance

    Because access to government information continues to be an area of concern for many U.S. citizens with disabilities, the U.S. government enacted Section 508 of the Rehabilitation Act in 2001 to ensure that government agencies create accessible Web content, enabling all citizens to access the information they need. A fully accessible Web site makes Web content accessible to all individuals, including those with disabilities, who may be accessing Web content via a variety of user agents. Common user agents include standard Web browsers, text-only browsers, assistive devices and mobile devices such as cell phones or personal digital assistants (PDAs).
    FREE! Go There Now!


    NEW! The dirty dozen: preventing common application-level hack attacks

    As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications.
    FREE! Go There Now!


    NEW! The role of integrated requirements management in software delivery

    This paper is about the critical role that a discipline called integrated require­ments management can play in helping to ensure that your business goals and IT investments are continuously aligned—whether you are sourcing, integrat­ing, building or maintaining software. It also looks at ways that automated IBM Rational® products can work together to help you use requirements in the very best way.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Performance Tester V7.0.1

    Get a free trial download of the latest version of IBM Rational Performance Tester V7.0.1, a load and performance testing solution for teams concerned about the scalability of their Web-based applications. Combining multiple ease-of-use features with granular detail, Rational Performance Tester simplifies the test-creation, load-generation and data-collection processes that help teams ensure the ability of their applications to accommodate required user loads.
    FREE! Go There Now!


    NEW! Webcast: Accelerating Software Innovation with System z

    Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, where he will overview Rational’s new offerings and programs to help customers accelerate software innovation on System z. He will discuss how these solutions help organizations extend their core business processes toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time.
    FREE! Go There Now!


    NEW! Webcast: IBM Rational Build Forge - Beyond the Build

    The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    ASP CODE ARTICLES

    - ASP Forms
    - ASP: The Beginning
    - Getting Remote Files With ASP Continued
    - Inbox and Outbox Manipulation in ASP
    - Relational DropDownList Using VB.NET
    - Ad Tracking URL Hits
    - Use ViewState to display one record per page...
    - Send Email using ASP.NET formatted in HTML
    - ASP File Explorer
    - ASP/XML Interview questions by Srivatsan Sri...
    - Various methods of setting Date values to a ...
    - Conditional DataGrid Item and using checkbox...
    - Fill .NET Listbox with SQL DataReader
    - Filling Dropdown box using Code-Behinds in C#
    - FLAMES code sample written in .NET What is F...

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT