Paging via ASP record

zhaozj2021-02-16  40

Introduction

The large recordset is displayed in the Active Server Pages (ASP) application, which is probably a problem you are familiar with. This article has been discussed in-depth discussion on this issue and its solutions and sample code. This sample code can be applied to your specific situation. This sample code is designed as a server-side solution, which is independent of the browser. In addition, I will point out the questions you need to consider when you design your own solution.

problem

Your query returns a large recordset. You need to provide a simple way to browse these results, that is, only the subset of results on each page. To effectively complete this job, you need to have an in-depth understanding of how ActiveX (R) data objects (ADO) and database work together.

solution

How to divide your record set into "page" instead of large-scale results? The so-called page, basically, you specify a lot of records that should be displayed together. For example, if you have 100 records in your record, you may display 10 records per page.

ADO provides two ways, PageSize and AbsolutePage. These methods allow you to specify the number of records to be displayed per page, and position the cursor on a page.

After opening the record set, the basic step is:

Specify PageSize for this recordset. It indicates the number of records to display per page. Specifies the ABSOLUTEPAGE of the recordset. This will record the pointer to the page of the page, the beginning of the page. Display the record page. To complete this step, you want to loop the entire recordset with the settings of the settings, or until the end of the file.

Sample code

The following example code illustrates the page establishment process. With it, you can build the prototype of your own solution. In your own code, make sure you want to complete the following steps:

Add an error handling. Add the limit on the number of records returned to the query. Record by condition filtration. (, For example, establish a WHERE clause). Use stored procedures or views.

Be sure to modify my sample code by changing the connection string and the SQL statement to point to your database. Since the code uses ADO constants, such as AdoSerServer, you must reference ADO TypeLibrary in your global.asa file, or include Adovbs.inc files in the ASP page. Note that Visual InterDev (R) automatically generates TypeLibrary references when you set the project reference to Microsoft ADO.

Note that there are two ways to provide a navigation bar:

Shownavbar. It provides users with a method of jumping to a specified page with a recording count (see Figure 1). To achieve this step, it uses the RecordCount and PageCount properties. Shownavbarfast. The method does not provide the ability to jump to the specified page, nor does it provide a record count, but can be retrieved by the Cachesize property (see Figure 2).

Pagethroughroughrs.asp

<% @ Language = VBScript%>

<% OPTION Explicit%>