<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <%Response.CodePage=65001%> <%Response.Charset="utf-8"%> <!-- 设置编码很重要,否则程序会出现异常或中文乱码问题。 --> <% 'conn '准备工作 dim conn dim connstr dim path path = server.mappath("\OneFCMS_Data\OneFCMS$%#$#Data$%#2012#$11$$#7.mdb") 'response.Write(path & "<br/>") 'on error resume next connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&path set conn=server.createobject("ADODB.CONNECTION") conn.open connstr If Err Then err.Clear Set Conn = Nothing Response.Write "数据库连接出错,请检查数据库连接文件中的数据库参数设置。" Response.End End If %> <% '获取当前页码 page=Request.QueryString("pid") set rs=server.createobject("adodb.recordset") exec="select * from News where ssfl = 1 order by zhiding desc,data desc " rs.open exec,conn,1,1 rs.PageSize = 10 '设置每页显示多少条记录 iCount=rs.RecordCount '总的记录数 iPageSize=rs.PageSize maxpage=rs.PageCount '页数 '对page页码的判断 if Not IsNumeric(page) or page="" then page=1 else page=cint(page) end if if page<1 then page=1 elseif page>maxpage then page=maxpage end if rs.AbsolutePage=Page '设置当前页码 if page=maxpage then x=iCount-(maxpage-1)*iPageSize '最后一页记录数不足PageSize情况。否则会报“在对应所需名称或序数的集合中,未找到项目。”错误信息~! else x=iPageSize end if For i=1 To x '循环显示 response.Write(rs("data") &"---"&rs("title")&"---") response.Write(formatdatetime(rs("data"),2) & "<br/>") '只显示日期,不显示时间函数处理。 rs.movenext next %> <%'以下显示分页 call PageControl2(iCount,maxpage,page,"border=0 align=center","<p align=center>") rs.close set rs=nothing %> <% '分页子程序 Sub PageControl2(iCount,pagecount,page,table_style,font_style) '生成上一页下一页链接 Dim query, a, x, temp action = "http://" & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("SCRIPT_NAME") query = Split(Request.ServerVariables("QUERY_STRING"), "&") action=a Response.Write("<table width=100% border=0 cellpadding=0 cellspacing=0 >" & vbCrLf ) Response.Write("<form method=get onsubmit=""document.location = '?pid='+ this.page.value;return false;""><TR >" & vbCrLf ) Response.Write("<TD align=left class=hui>" & vbCrLf ) Response.Write(font_style & vbCrLf ) 'response.Write "<A href=javascript:history.back()>【返回前页】</a> " if page<=1 then Response.Write ("首页 " & vbCrLf) Response.Write ("上一页 " & vbCrLf) else Response.Write("<A HREF=?" & ad & "pid=" & "1>首页</A> " & vbCrLf) Response.Write("<A HREF=?" & ad & "pid=" & (Page-1) & ">上一页</A> " & vbCrLf) end if if page>=pagecount then Response.Write ("下一页 " & vbCrLf) Response.Write ("尾页 " & vbCrLf) else Response.Write("<A HREF=?" & ad & "pid=" & (Page+1) & ">下一页</A> " & vbCrLf) Response.Write("<A HREF=?" & ad & "pid=" & pagecount & ">尾页</A> " & vbCrLf) end if Response.Write("页次:" & page & "/" & pageCount & "页"& vbCrLf) Response.Write(" 共" & iCount & "条记录" & vbCrLf) Response.Write(" 转" & "<INPUT CLASS=wenbenkuang TYEP=TEXT NAME=page SIZE=2 Maxlength=5 VALUE=" & page & ">" & "页" & vbCrLf & "<INPUT CLASS=go-wenbenkuang type=submit value=GO>") Response.Write("</TD>" & vbCrLf ) Response.Write("</TR></form>" & vbCrLf ) Response.Write("</table>" & vbCrLf ) End Sub %>