ASP page display

zhaozj2021-02-11  194

ASP page display

If you have used the electronic bulletin board on many websites, then you should know that the electronic bulletin program is to increase the page read speed.

Generally don't list all the posts in one page, but divide them into multi-page display, each page

Show a number of posts, such as 20. Do you want to know how to implement pagination display? Please see

This article!

So how do you want to display the database's query result paging? In fact, there are many ways.

But there are two main types:

First, read all the records in the database in accordance with the query conditions in the database, read in the Recordset.

Store in memory, then several special support panesses provided by the ADO Recordset object

Property: PageSize (Page size), PageCount (number of pages) and

AbsolutePage (absolute page) to manage paging processing.

Second, according to the customer's instruction, each time respectively, from the record of the query condition, the specified number

The record number is read and displayed.

The main difference between the two is that the former is one-time to read all records in memory and then according to the instructions.

To make judgment analysis to achieve the effect of paging display, the latter is to make judgments according to the instructions

Read the specified number of records that meet the query criteria, so that the features of the paging display are directly reached.

We can feel obvious that when the number of records in the database reaches tens of thousands or more, the first

The implementation efficiency of the method will be significantly lower than the second method, because when each customer query page is

Store all eligible records in server memory, and then processed by paging, if

At the same time, there are more than 100 customer online queries, then the execution efficiency of the ASP application will be large.

influences. However, when the number of records on the server and the number of online people are not a lot,

The two are different in operation, and the first method is generally used in this time because the first

Method's ASP program preparations relative second method should be simple and clear.

Here, the author takes advantage of our common ASP BBS program to analyze how

Implement the paging display in the BBS program, due to the database of BBS programs we generally used

The number of records and the number of people visited will not be too much, so the following program instance is the previous introduction.

The first paging display method.

Paging display when using ADO access database, is actually a record of Recordset

Operation. So we must first learn about the properties and methods of the REORDSET object:

BOF attribute: The current indicator refers to the first pen of Recordset.

EOF attribute: The current indicator refers to the last pen of Recordset.

MOVE method: Move the indicator to a record in the Recordset.

AbsolutePage Properties: Which page is located in the location of the current record?

AbsolutePosition Attribute: The location of the current indicator in the Recordset.

PageCount Properties: Displays the Recordset object that includes how much "page".

PageSize Attribute: Displays the number of records displayed in each page of the Recordset object.

RecordCount Properties: Displays the total number of recordset object records.

Let's let us know more about these important properties and methods.

First, Bof and EOF attribute

Usually we write code in the ASP program to verify BOF and EOF properties, thus

The location of the Recordset, which is currently pointed to by the indicator, can learn about the BOF and EOF properties.

Does a RecordSet object contain a record or know if the mobile record line has exceeded

The range of Recordset objects.

Such as: <% if not rs.eof the ...%> <% if not (rs.bof and %e)%>

If the location of the current record is before the first line of Recordset objects, BOF

The property returns true, and then false returns FALSE.

If the current recorded position is after a recording record last line record,

The EOF property returns true, and then returns false.

BOF and EOF are false: indicates that the indicator is located in the Recordset.

BOF is true: The current indicator refers to the first record of the Recordset.

EOF is True: The current indicator refers to the last record of the Recordset.

Bof and EOF are True: There is no record in the Recordset.

Second, MOVE method

You can use the MOVE method to move the indicator to a record in the Recordset, the syntax is as follows:

Rs.Move NumRecords, Start

The "RS" here is an object variable, indicating that one wants to move when the current record position

Recordset object; "NUMRECORDS" is a positive and negative number, setting the current record location

Movement; "start" is an optional item that specifies the label that records the starting.

All Recordset objects support Move methods if NumRecords parameters

Big than zero, the current record position moves in the end of the end; if it is less than zero, the current record location

Move in the direction of the beginning; if an empty RecordSet object calls the MOVE method,

Generate an error.

MoveFirst method: Move the current recording location to the first record.

MoveLAST method: Move the current record position to the last record.

MoveNext method: Move the current recording location to the next record.

MovePRevious method: Move the current record position to the previous record.

Move [N] Method: Move indicator to the nth record, N is calculated from 0.

Third, absolutePage properties

AbsolutePage Properties Setting the location of the current record is where the page number is located;

Use the PageSize property to divide the RecordSet object into logical pages, records for each page

The number is PageSize (except for the last page may have less than the number of records of the PageSize). Here

Be careful not to support this attribute, so be careful when using it.

As with the AbsolutePosition property, the AbsolutePage property is starting with 1

If the current record of Recordset is currently recorded, AbsolutePage is 1. can

Set the AbsolutePage property to move to the first row record location of a specified page.

Fourth, AbsolutePosition Attribute

If you need to determine the location of the current indicator in the Recordset, you can use

AbsolutePosition attribute.

The value of the absolutePosition attribute is the current indicator relative to the first position, from 1

Mandarin, the first AbsolutePosition is 1.

Note that when accessing RecordSet, it is not possible to ensure that RecordSet is the same.

The order appears.

To enable AbsolutePosition, you must first set to use the user end.

The CURSOR (pointer), the ASP code is as follows:

rs2.cursorlocation = 3 5, PageCount properties

Using the PageCount property, determine the data of the Recordset object including how much "page".

The "page" here is the collection of data records, the size is equal to the setting of the PageSize property, even

The number of records is less than the value of PageSize, and the last page is also a page of PageCount.

It is important to note that all data providers support this attribute.

6. PageSize property

The PageSize property is how to make a pagination display when the ADO access database is determined.

You can decide how much records make up a logically "one page". Set and build a size of a page,

This allows the first record that allows the AbsolutePage property to move to other logical pages.

The PageSize property is set at any time.

Seven, RecordCount properties

This is also a very common and important attribute, we often use the RecordCount property to find

A RecordSet object includes how many records. Such as:

<% TOTLE = rs.Recordcount%>

After understanding the above properties and methods of the Recordset object, let's consider it.

How to use them to reach our pagination display. First, we can be the PageSize property.

Set a value to specify the number of rows that make up from the record group; then pass

RecordCount property to determine the total number of records; re-use the total number of records to be available in PageSize

To the total number of pages displayed; Finally, access to the specified page via the AbsolutePage property.

It seems that it is not complicated. Let's take a look at how the program is implemented?

We establish such a simple BBS application, which have the following five in their databases, respectively.

Field: "ID", automatic number of each post; "Subject", the topic of each post;

"Name", the name of the user; "email", the user's email address;

"Postdate", the time of the addition. The DSN of the database is "BBS". We will show the post

All steps for paging are placed in a process called "showlist ()", which is convenient to call.

The procedure is as follows:

'---- BBS Display Posts Page ----

<% Sub showlist ()%>

<%

PGSZ = 20 'setting switch, specify the number of posts shown in each page, default is 20 sheets

Set conn = server.createObject ("adoDb.connection")

SET RS = Server.createObject ("AdoDb.Recordset")

SQL = "SELECT * from message Order by id"

'Query all posts and follow the ID of the post

Conn.open "BBS"

RS.Open SQL, CONN, 1, 1

IF = 0 THEN

Response.write "

Sorry, there is no relevant information in the database!

Else

Rs.pagesize = cint (pgsz) Set the value of the PageSize property

Total = int (rs.recordcount / pgsz * -1) * - 1 'calculates the total number of displayed pages

Pageno = Request ("Pageno")

IF Pageno = "" ""

Pageno = 1

Else

Pageno = PAGENO 1

Pageno = PAGENO-1

END IF

Scrolaction = Request ("scroll")

IF scrollAction = "Previous" THEN

Pageno = PAGENO-1

END IF

If scrollAction = "Next page" THEN

Pageno = PAGENO 1

END IF

IF Pageno <1 THEN

Pageno = 1

END IF

n = 1

Rs.absolutePage = Pageno

Response.write "

"

Position = rs.pagesize * Pageno

Pagebegin = position-rs.pageSize 1

IF position

Pagend = position

Else

Pagend = rs.Recordcount

END IF

Response.write "

database query results: "

Response.write "(a total of" & RS.RecordCount & "strips meet the requirements,

Show "& Pagebegin &" - ​​"& Pagend &") "

Response.write "

Cellspacing = 0 bgcolor = # ffffff> "

Response.write "

"

Do While Not (RS Is Nothing)

Rowcount = rs.pageSize

Do While Not Rs.eof and Rowcount> 0

IF n = 1 THEN

Response.write "

"

Else

Response.write "

"

END IF

n = 1-n%>

Topic

User email

Release Date

Value = 'Previous'> "

END IF

If rowcount = 0 and Pageno <> Total Then

Response.write " "

END IF

Response.write ""

END IF

%>

<% End sub%>

I believe everyone should fully understand the above procedure, so it is not explained in detail here.

It is worth noting that a small skill is used in this program

Name = "Pageno" value = "<% = Pageno%>">, this is used to call it each time

The "dark road" of the data is passed when the ASP file is transferred, because we need to pass the representative when the program is called

The parameters of the current page number may, you may think of the use of session, but from saving system resources and

Generality is in this way, with such a hidden form will be used to achieve a better effect.

转载请注明原文地址:https://www.9cbs.com/read-4143.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.032, SQL: 9