Object-oriented ASP programming 2-Paging object (JavaScript Version)

Source: Internet
Author: User
Tags rowcount

Component-Based ASP programming 2-Paging object

 

In ASP, the most commonly used program segments are called by writing pages as functions. Many parameters need to be passed and written as objects to enable paging.

Object calling is simple. Based on the paging functions of many netizens, this article uses JavaScript to write a object

Under the folder "_ scriptcom", the file name is "jpagenavbar. asp". Let's take a look at the calling method of the paging object (because most ASP developers

Use Vbscript, so this example is written in VBScript ):
<% @ Language = "VBScript" %>
<! -- # Include file = "../connections/dbconn. asp" -->
<! -- # Include file = "../_ scriptcom/fadodb. asp" -->
<! -- # Include file = "../_ scriptcom/fsession. asp" -->
<! -- # Include file = "../_ scriptcom/jpagenavbar. asp" -->
<%
Response. Buffer = true
On Error resume next

If trim (request. servervariables ("request_method") = "Post" then
'Get the query string
Chxstr = readform ("chxstr ")
Xshstr = readform ("xshstr ")
R1 = readform ("R1 ")
'Save the query Condition
Session ("R1") = r1
Session ("chxstr") = chxstr
Session ("xshstr") = xshstr
Else
If it is not submitted from form, it is a paging query condition obtained from session
R1 = readsession ("R1 ")
Chxstr = readsession ("chxstr ")
Xshstr = readsession ("xshstr ")
End if

'Here are some logic operations about the business.
If xshstr = empty then
Xshstr = "querying all records"
End if

Select case r1
Case 1 'students at school
SQL = "select * From v_student_base where graduate = 0"
If chxstr <> empty then
SQL = SQL + "and" + chxstr
End if
Cddr = "Students in School"
Case 2 'graduate student
SQL = "select * From v_student_base where graduate = 1"
If chxstr <> empty then
SQL = SQL + "and" + chxstr
End if
Cddr = "Graduation student"
Case 0' all students
If chxstr <> empty then
SQL = "select * From v_student_base where" + "" + chxstr
Else
SQL = "select * From v_student_base"
End if
Cddr = "all students"
Case else
Response. Write "system parameter error. Please contact the system administrator! "
Response. End
End select

'Generate connection and recordset
Set conn = conncreate (getdblink ())
Set rs = rscreate ()
Rs. Open SQL, Conn, 1, 3
If (Rs. EOF) then
Show_msg "Sorry, there is no record you want! ", 4," infoquery. asp"
End if
Dim Gd (1)
Gd (0) = "not graduated"
Gd (1) = "graduated"
 
'*************************************** ************************************
'Note: the page is displayed.
Rowcount = 15
Set FY = createjpagenavbar ()
If (not isempty (RS) then
Rs. pagesize = rowcount 'sets the page record of the dataset.
FY. pagesize = rowcount
Rs. absolutepage = FY. getcurrentpage ()
FY. recordcount = Rs. recordcount
FY. pagecount = Rs. pagecount
FY. pnwidth = "100%"
FY. pnalign = "center"
FY. plwidth = "100%" 'table width
FY. plalign = "right" 'table alignment
End if
'*************************************** **************************************** ****
%>
<HTML>
<Head>
<Title> Student Information Query </title>
<Link href = "../CSS/style.css" rel = "stylesheet" type = "text/CSS">
</Head>
<Body text = "#000000" bgcolor = "# ffffff" leftmargin = "0" topmargin = "0">
<Br>
<Table width = "550" border = "1" cellspacing = "0" cellpadding = "1" align = "center" class = "t_table"

Id = "Table1">
<Tr>
<TD colspan = "2" class = "t_head" >::: student information search result: </TD>
</Tr>
<Tr>
<TD width = "80%" align = "Left"> <B >=& gt; & gt; query condition: </B> <% = xshstr %> </TD>
<TD width = "20%" align = "right"> <input type = "button" value = "return" class = "button"

Onclick = "gofind ()" id = "button1" name = "button1"> </TD>
</Tr>
<Tr>
<TD colspan = "2"> <Table width = "100%" border = "0" cellpadding = "1" cellspacing = "0"

Class = "t_table" id = "Table2">
<Tr align = "center">
<TD colspan = "7"> <%
'*************************************** ************
FY. pndisplay () 'paginated "Previous Page" "next page"
'*************************************** ********************
%> </TD>
</Tr>
<Tr>
<TD width = "13%" class = "t_head"> Student ID </TD>
<TD width = "11%" class = "t_head"> name </TD>
<TD width = "8%" class = "t_head"> gender </TD>
<TD width = "10%" class = "t_head"> Grade </TD>
<TD width = "20%" class = "t_head"> major </TD>
<TD width = "28%" class = "t_head"> secondary school </TD>
<TD width = "10%" class = "t_head"> Status </TD>
</Tr>
<% I = 0
'*************************************** *****************
While (not Rs. EOF and I <rowcount) 'controls the number of records displayed on one page
'*************************************** ******************
%>
<Tr>
<TD width = "13%" align = "center"> <a href = "#" onclick = "openwindow2 ('stu _ msg. asp?

Stu_num = <% = RS ("stu_num") %> ') "> <% = RS (" stu_num ") %> </a> </TD>
<TD width = "11%" align = "center"> <% = RS ("name") %> </TD>
<TD width = "8%" align = "center"> <% = RS ("sex") %> </TD>
<TD width = "10%" align = "center"> <% = RS ("gread") %> </TD>
<TD width = "20%" align = "center"> <% = RS ("speciality_name") %> </TD>
<TD width = "28%" align = "center"> <% = RS ("secondary") %> </TD>
<TD width = "10%" align = "center"> <% = Gd (RS ("graduate") %> </TD>
</Tr>
<% I = I + 1
Rs. movenext
Wend %>
<Tr align = "right">
<TD colspan = "7"> <%
'*************************************** ***********************
FY. pldisplay () 'paging list
'*************************************** ***********************
%> </TD>
</Tr>
</Table> </TD>
</Tr>
</Table>
</Body>
</Html>
<%
Rsnull (RS)
Connnull (conn)
%>

This is displayed by PAGE (after processing)

Here is the source code

<Script language = JavaScript runat = Server>
//************************************** **********************************
// Script compont Object Model
// Design for Active Server Pages
//
// Copyright 2003 version 1.0
// Made by newsunet
// Do not delete this comment, spread it freely, and retain ownership
//************************************** **********************************

/* // ADO. recordset record page object
// Set pagination
VaR rowcount = 3
VaR FY = new jpagenavbar ()
If (! Rsrpt. EOF ){
Rs. pagesize = rowcount // set the page record of the dataset
FY. pagesize = rowcount
Rs. absolutepage = FY. getcurrentpage ()
FY. recordcount = Rs. recordcount
FY. pagecount = Rs. pagecount
FY. pnwidth = "100%"
FY. pnalign = "right"
FY. plwidth = "100%" // table width
FY. plalign = "right" // table alignment

}
// Display the page
<% FY. pndisplay () %>
<% FY. pldisplay () %>

*/
Function createjpagenavbar (){

// This function is an interface function of VBScript. VBScript is not an object-based scripting language.
VaR objjpagenavbar = new jpagenavbar
Return objjpagenavbar
}
Function jpagenavbar (){
// Public members
This. pagesize = "0"
This. recordcount = "0" // total number of records
This. pagecount = "1" // total number of pages
This. currentpage = "1"

This. pnwidth = "100%"
This. pnalign = "right"
This. plwidth = "100%" // table width
This. plalign = "right" // table alignment

// Private Members

// Public methods
This. getcurrentpage = _ getcurrentpage
This. pndisplay = _ pn_show;
This. pldisplay = _ pl_show;
 
// Private methods

}
 
Function _ getcurrentpage (){
// The page number currently displayed

// Obtain the current page
VaR pageno = request. querystring ("pageno ")
// If no page is selected, the first page is displayed by default;
If (isnan (pageno )){
Pageno = 1
}
This. currentpage = pageno
Return pageno
}
Function _ pl_show (){

VaR strbuilder = new string ()
Strbuilder = ""
VaR P = (this. currentpage-(this. currentpage % 10)/10 // calculate the number of pages displayed on the page
// The first group is 0th

Strbuilder + = "<Table border =/" 0/"cellpadding =/" 0/"cellspacing =/" 0 /""
Strbuilder + = "width =/" "+ this. plwidth +"/"align =/" "+ this. plalign +"/">"

Strbuilder + = "<tr>"
Strbuilder + = "<TD valign =/" middle/"align =/" right/"> page :"

If (this. currentpage = 1 ){
Strbuilder + = "<font face =/" webdings/"color =/" # ff0000/"> 9 </font>"
}
Else {
Strbuilder + = "<a href = /"? Pageno = 1/"Title =/" homepage/"> <font face =/" webdings/"> 9 </font> </a>"
}
// Last 10 pages
If (p * 10> 0 ){
Strbuilder + = "<a href = /"? Pageno = "+ (p * 10) +"/"Title = Top 10 pages> <font

Face =/"webdings/"> 7 </font> </a>"
}
Strbuilder + = "<B>"
// Paging list
For (VAR I = p * 10 + 1; I <= p * 10 + 10; I ++ ){
If (I = This. currentpage ){
Strbuilder + = "<font color =/" #000000/">" + I + "</font>"
}
Else {
Strbuilder + = "<a href =? Pageno = "+ I +" Title =/"to" + I + "Page/"> "+ I +" </a>"
}
If (I> = This. pagecount) break;
}
Strbuilder + = "</B>"
// Display the next 10 pages
If (I <this. pagecount ){
Strbuilder + = "<a href = /"? Pageno = "+ I +"/"Title =/" next 10 pages/"> <font

Face =/"webdings/"> 8 </font> </a>"
}
// Display the last page
If (this. currentpage = This. pagecount ){
Strbuilder + = "<font face =/" webdings/"color =/" #000000/">:</font>"
}
Else {
Strbuilder + = "<a href =? Pageno = "+ this. pagecount +" Title =/"last page/"> <font

Face =/"webdings/" >:</font> </a>"
}
Strbuilder + = "</TD> </tr> </table>"
Response. Write (strbuilder)
}
Function _ pn_show (){
VaR strbuilder = new string ()
VaR nextpageno
Strbuilder = ""
Strbuilder + = "<Table border =/" 0/"cellpadding =/" 0/"cellspacing =/" 0 /""
Strbuilder + = "width =/" "+ this. pnwidth +"/"align =/" "+ this. pnalign +"/">"
Strbuilder + = "<tr>"
Strbuilder + = "<TD valign =/" middle/"> page times:

[<B> "+ this. currentpage + "</B>/<B>" + this. pagecount + "</B>] Page [<B>" + this. pagesize + "</B>] total records

Count: [<B> "+ this. recordcount +" </B>] </TD>"
Strbuilder + = "<TD align =/" right/">"
If (this. currentpage> 1 ){
Nextpageno = This. currentpage
Nextpageno --
Strbuilder + = "[<a href =? Pageno = "+ nextpageno +" Title =/"go to previous page/"> previous page </a>]"
}
If (this. currentpage <this. pagecount ){
Nextpageno = This. currentpage
Nextpageno ++
Strbuilder + = "[<a href =? Pageno = "+ nextpageno +" Title =/"go to the next page/"> next page </a>]"
}
Strbuilder + = "</TD> </tr> </table>"
Response. Write (strbuilder)
}

</SCRIPT>

The original name of this article: Component-Based ASP programming 2 -- paging object

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.