Pagination | Page one. About parameter passing. If there are 46 records in the table and then we typed http.//localhost/display.asp?line=10&page=2 in the address bar (assuming this is the correct path), the browser will show us the 10 records for the second page. But if you only typed http.//localhost/display.asp in the address bar, the browser gave us an error message. How to solve it? We must add a judgment when reading these parameters, and if the argument is empty, assign it an initial value to prevent errors. Replace the read user requirements by section with the following code:
<%
If Request ("page") <> "then
Page=cint (Request ("page")
Else
Page=1 '-------If the argument page is empty, assign it a value of 1
End If
If Request ("line") <> "then
Line=cint (Request ("line"))
Else
line=10 '-------If the argument line is empty, assign it a value of 10
End If
%>
Two The rationality problem of the parameter. What would happen if we typed http.//localhost/display.asp?line=20&page=4 in the address bar? The browser complains. Because there are only 46 records in the table, and we want it to show 20 on each page, 20 on page fourth, that is, 61st to 80th record. There's obviously going to be a mistake. The same situation will also appear in the navigation bar, if the current browser is displayed in 10 per page, page Fourth of the content, we go to set it to 20 per page display, but also error. The solution is the same, first judge the rationality of the parameters, and then set the display mode. Replace the following code with the "set the display by user Requirements" section.
<%
If page> (Rs. RECORDCOUNT-1) \line+1 Then
'-------calculated by calculation, the maximum number of pages = (Total records-1) \ Number of rows per page +1
Response.Write ("error!") '-------If the argument is not realistic, output ' error! '
Response.End '-------Termination procedure
End If
Rs. Pagesize=line
Rs. Absolutepage=page
%>
Three Verify the form field. All two input text boxes in the navigation bar must be entered as integers, otherwise there will be an error. We can take advantage of FrontPage's Validation form field feature to finish, here is not much to say.
Four Optimization. So far, there is one drawback to this program. In the database access process, the most time-consuming is the database open and Recordset object, and this program every execution will open the database and set up the Recordset object, greatly reduce the efficiency, once the access volume increases, this program is to value. The solution is to open the database and set up the Recordset object the first time the program is executed, and then return the values in the session as soon as the next execution. Replace the "Open Database and Tables" section with the following code.
<%
If not IsObject (session ("Conn")) Then
Set Conn=server.createobject ("ADODB. Connection ")
Filepath=server.mappath ("Abc.mdb")
Conn. Open "Driver={microsoft Access driver (*.mdb)};d bq=" & filepath
Set Rs=server.createobject ("ADODB. Recordset ")
Rs.Open "Main", conn,3,2
Set session ("Conn") =conn
Set session ("RS") =rs
Else
Set Conn=session ("conn")
Set Rs=session ("RS")
End If
%>
At this point, a more "perfect" program is completed.