When programming ASP databases, due to browser size restrictions, when there are many data records to be browsed, in order to achieve more intuitive results, we divide these data records into several pages and use the data navigation buttons or other hyperlinks) to browse through pages. In fact, the paging browsing of such data records can also be implemented in ASP. NET. In addition, the implementation process is clearer and easier than the ASP processing process.
There are two basic types of browser-based paging data records. Other types of page views can be either modified or integrated. The following figure shows the specific expression:
Figure 01: Data Record pattern browsing by PAGE
Figure 02: Second paging data record Style
The following describes how to implement these two types of paging data records in ASP. NET:
First, let's introduce the database we use. In this article, we use the local database Access 2000 and the database name is "Data. mdb, which stores a data table "tblItem ". The structure of this data table is as follows:
| Field name |
Field Type |
| ItemID |
Automatic ID |
| ItemName |
Text Type |
If you are using another database, simply modify the program described below. This will be introduced below.
I. software environment for program design and operation in this article:
1). Microsoft Windows 2000 Server Edition
2). Net FrameWork SDK Beta 2
II. Key Steps and implementation methods of the first paging data record:
1) first, you must obtain the hyperlink string of the initial browsing data record:
This is actually very important, because operations such as "Homepage" and "next page" in the first type of page view are implemented by adding parameters of the page to be browsed after the hyperlink string, the program in this article is implemented through the GetPageName () function. This function is as follows:
Function GetPageName () As String Dim Str As String Dim Pos As Short Str = Request. ServerVariables ("Script_Name"). Trim () Pos = Str. LastIndexOf ("/") If Pos> = 0 Then Return Str. SubString (Pos + 1) Else Return Str End If End Function |
2). Obtain the total number of data records you want to browse:
In this article, we use all the records in the data table "tblItem" for viewing convenience. The ASP. NET page uses ADO. NET to obtain the data table "tblItem ". The following code uses ADO. NET to obtain the total number of records in the tblItm table:
<% @ Page Language = "VB" %> <% @ Import Namespace = "System. Data" %> <% @ Import Namespace = "System. Data. OleDb" %>
|