ASP分页函数

来源:风之相随'S BLOG 时间:2009-07-06 12:41:00 

 

<%
'***********************************************
'函数名:JoinChar
'作  用:向地址中加入 ? 或 &
'参  数:strUrl  ----网址
'返回值:加了 ? 或 & 的网址
'***********************************************
function JoinChar(strUrl)
if strUrl="" then
  JoinChar=""
  exit function
end if
if InStr(strUrl,"?")<len(strUrl) then 
  if InStr(strUrl,"?")>1 then
   if InStr(strUrl,"&")<len(strUrl) then 
    JoinChar=strUrl & "&"
   else
    JoinChar=strUrl
   end if
  else
   JoinChar=strUrl & "?"
  end if
else
  JoinChar=strUrl
end if
end function
'**************************************************
'过程名:showpage
'作  用:显示“上一页 下一页”等信息
'参  数:sfilename  ----链接地址
'       totalnumber ----总数量
'       maxperpage  ----每页数量
'       ShowTotal   ----是否显示总数量
'       ShowAllPages ---是否用下拉列表显示所有页面以供跳转。有某些页面不能使用,否则会出现JS错误。
'       strUnit     ----计数单位
'**************************************************
sub showpage(sfilename,totalnumber,maxperpage,ShowTotal,ShowAllPages,strUnit)
dim n, i,strTemp,strUrl
if totalnumber mod maxperpage=0 then
     n= totalnumber \ maxperpage
   else
     n= totalnumber \ maxperpage+1
   end if
   strTemp= "<table align='center'><tr><td><font size='2'>"
if ShowTotal=true then 
  strTemp=strTemp & "共 <b>" & totalnumber & "</b> " & strUnit & "  "
end if
strUrl=JoinChar(sfilename)
   if CurrentPage<2 then
      strTemp=strTemp & "首页 上一页 "
   else
      strTemp=strTemp & "<a href='" & strUrl & "page=1'>首页</a> "
      strTemp=strTemp & "<a href='" & strUrl & "page=" & (CurrentPage-1) & "'>上一页</a> "
   end if
   if n-currentpage<1 then
      strTemp=strTemp & "下一页 尾页"
   else
      strTemp=strTemp & "<a href='" & strUrl & "page=" & (CurrentPage+1) & "'>下一页</a> "
      strTemp=strTemp & "<a href='" & strUrl & "page=" & n & "'>尾页</a>"
   end if
    strTemp=strTemp & " 页次:<strong><font color=red>" & CurrentPage & "</font>/" & n & "</strong>页 "
    strTemp=strTemp & " <b>" & maxperpage & "</b>" & strUnit & "/页"
if ShowAllPages=True then
  strTemp=strTemp & " 转到:<select name='page' size='1' onchange=""javascript:window.location='" & strUrl & "page=" & "'+this.options[this.selectedIndex].value;"">"   
     for i = 1 to n   
      strTemp=strTemp & "<option value='" & i & "'"
   if cint(CurrentPage)=cint(i) then strTemp=strTemp & " selected "
   strTemp=strTemp & ">第" & i & "页</option>"   
     next
  strTemp=strTemp & "</select>"
end if
strTemp=strTemp & "</font></td></tr></table>"
response.write strTemp
end sub
%>

列表页面的代码



<%
const MaxPerPage=15
dim totalPut,CurrentPage,TotalPages
dim strFileName
dim strEmplName
strEmplName = strReplace(request("emplName"))
strFileName="employeeList.asp?emplName="&strEmplName&""
if request("page")<>"" then
    CurrentPage=cint(request("page"))
else
CurrentPage=1
end if
%>
<form name="form1" method="post" action="">
用户名:<input name="emplName" type="text" class="myinput" id="emplName">
<input name="Submit" type="submit" class="mybutton" value="提交">
</form>
<table width="100%" border="1" cellspacing="1" cellpadding="5" id="bgtable">
  <tr>
    <td colspan="6" align="center" id="bgtitle">员工列表</td>
  </tr>
  <tr>
    <td width="13%" align="center" id="bgtitle">用户名</td>
    <td width="13%" align="center" id="bgtitle">姓名</td>
    <td width="20%" align="center" id="bgtitle">所属部门</td>
  </tr>
<%
sql = "select * from admin_employee where flag <> 1"
if strEmplName = "" then
  sql = sql
else
  sql = sql&" and userName like '%"&strEmplName&"%'"
end if
rs.open sql,conn,1,1
if not(rs.bof and rs.eof) then
   totalPut=rs.recordcount
  if currentpage<1 then
         currentpage=1
     end if
     if (currentpage-1)*MaxPerPage>totalput then
      if (totalPut mod MaxPerPage)=0 then
        currentpage= totalPut \ MaxPerPage
     else
         currentpage= totalPut \ MaxPerPage + 1
      end if
     end if
  if currentPage=1 then
         showContent
         showpage strFileName,totalput,MaxPerPage,true,true,""
      else
          if (currentPage-1)*MaxPerPage<totalPut then
              rs.move  (currentPage-1)*MaxPerPage
           dim bookmark
             bookmark=rs.bookmark
             showContent
             showpage strFileName,totalput,MaxPerPage,true,true,""
         else
          currentPage=1
             showContent
             showpage strFileName,totalput,MaxPerPage,true,true,""
      end if
  end if
    rs.Close
sub showContent()
    dim i
    i=0 
    do while not rs.eof
%>
<tr>
    <td align="center" id="bkbody"><%=rs("userName")%></td>
    <td align="center" id="bkbody"><%=rs("realName")%></td>
    <td align="center" id="bkbody"><%=rs("deptName")%></td>
</td>
  </tr>
<%
i=i+1
if i>=MaxPerPage then exit do
rs.MoveNext
    loop
end sub
else
%>
  <tr>
    <td colspan="6" align="center" id="bkbody">暂时还没有员工信息!</td>
  </tr>
<%
end if
%>
</table>

标签:asp,分页,函数
0
投稿

猜你喜欢

  • 条件注释使用指南[译]

    2009-03-23 17:41:00
  • Xml Http抓取数据时乱码问题解决

    2008-04-24 11:16:00
  • js表单提交显示进度条

    2007-09-18 13:10:00
  • 巧用Dreamweaver MX共享Execl XP文件

    2009-07-14 21:56:00
  • 基于ASP的站内多值搜索

    2010-05-11 20:03:00
  • 文字超长自动省略,以...代替,CSS实现

    2009-07-16 10:15:00
  • 一种特别简单的MySQL数据库安装方法

    2008-12-17 15:30:00
  • 服务端XMLHTTP(ServerXMLHTTP in ASP)基本应用(上)

    2008-11-11 12:49:00
  • MySQL Explain命令用于查看执行效果

    2009-02-27 15:30:00
  • 简单实现Standby SQL Server 数据库的方法

    2009-10-23 09:26:00
  • Linux下MySQL整个数据库的备份与还原

    2008-12-29 13:20:00
  • SQL学习笔记三 select语句的各种形式小结

    2011-09-30 11:09:31
  • 关于Ajax responseText 中文乱码问题

    2008-02-12 16:30:00
  • msxml3.dll (0x80070005)拒绝访问 解决方法

    2010-03-11 21:26:00
  • 使用SQL语句快速获取SQL Server数据字典

    2009-01-08 16:31:00
  • Oracle 数据库中创建合理的数据库索引

    2009-07-02 12:31:00
  • 网站浏览器兼容的底线

    2007-12-22 11:26:00
  • 如何调试 XMLHttpRequest

    2008-08-15 13:59:00
  • 建立MySQL数据库日常维护规范

    2009-03-20 12:34:00
  • SQL注入攻击成为新威胁将挑战操作系统安全

    2009-03-16 15:13:00
  • asp之家 网络编程 m.aspxhome.com