asp分页(自己整理的2个分页程序)

2018-09-06 12:07

阅读:442

  <%@LANGUAGE=VBSCRIPTCODEPAGE=936%>
<!DOCTYPEhtmlPUBLIC-//W3C//DTDXHTML1.0Transitional//EN
<htmlxmlns=
<head>
<metahttp-equiv=Content-Typecontent=text/html;charset=gb2312/>
<title>asp分页程序</title>
<styletype=text/css>
<!--
.STYLE1{font-size:12px}
-->
</style></head>

<body>
<p>
<tablewidth=186height=39border=1cellpadding=0cellspacing=0>
<tr>
<td>姓名</td>
<td>密码</td>
</tr>
<%
setrs=server.createobject(adodb.recordset)
conn=DBQ=+server.mappath(zheng.mdb)+;DefaultDir=;DRIVER={MicrosoftAccessDriver(*.mdb)};
sql=select*fromuser

rs.opensql,conn,1,2
rs.pagesize=6设置页面显示得页数
ifrequest(page)<>then
epage=cint(request(page))
ifepage<1thenepage=1
ifepage>rs.pagecountthenepage=rs.pagecount
else
epage=1
endif
rs.absolutepage=epage
fori=0tors.pagesize-1
ifrs.boforrs.eofthenexitfor
%><tr>
<td><%=rs(name)%></td>
<td><%=rs(pass)%></td>
</tr>


<%
rs.movenext
next
%>
</table>
<divalign=left><spanclass=STYLE1>
<formmethod=getonsubmit=document.location=c.asp?Page=+this.page.value;returnfalse;>
<%ifepage=1thenresponse.Write(首页)elseresponse.Write(<ahref=c.asp?page=1>&首页&</a>)%>

<%ifepage=1thenresponse.write(上一页)elseresponse.write<ahref=c.asp?page=&epage-1&>上一页</a>%>

<%ifepage=rs.pagecountthenresponse.write(下一页)elseresponse.write<ahref=c.asp?page=&epage+1&>下一页</a>%>

<%ifepage=rs.pagecountthenresponse.write(末页)elseresponse.write<ahref=c.asp?page=&rs.pagecount&>末页</a>%>
现在是第<fontcolor=red><%=epage%></font>页一共有<fontcolor=red><%=rs.pagecount%></font>页
<inputname=pagevalue=<%=epage%>maxlength=5tyep=text/>

<inputtype=submitvalue=GOstyle=font-size:12px;border:1pxsolid#CCCCCC;width:23px;/></form>
</div>
<p></p>
<p>
<%

name=request(name)
pass=request(pass)
ifname<>andpass<>then
rs.Addnew
rs(name)=name
rs(pass)=pass
rs.update
rs.close
endif
%>
</p>
</p>
<formid=form1name=form1method=postaction=>
<p>
<inputname=nametype=textid=name/>
</p>
<p>
<inputname=passtype=textid=pass/>
<inputtype=submitname=Submitvalue=提交/>
</p>
</form>
<p>
<tablewidth=63%border=0cellpadding=0cellspacing=1bgcolor=#0000FFstyle=border-collapse:collapse>
<%
setmrs=server.createobject(adodb.recordset)
conn=DBQ=+server.mappath(zheng.mdb)+;DefaultDir=;DRIVER={MicrosoftAccessDriver(*.mdb)};
sql=select*fromuser

mrs.opensql,conn,1,1
IfmRs.bofandmRs.eofthen
Response.Write<span>没有任何记录</span>
Response.End
Else
mRs.PageSize=6每页记录条数
iCount=mRs.RecordCount记录总数
iPageSize=mRs.PageSize
maxpage=mRs.PageCount
page=request(page)

IfNotIsNumeric(page)orpage=then
page=1
Else
page=cint(page)
EndIf
Ifpage<1then
page=1
ElseIfpage>maxpagethen
page=maxpage
EndIf
mRs.AbsolutePage=Page
Ifpage=maxpagethen
x=iCount-(maxpage-1)*iPageSize
Else
x=iPageSize
EndIf
EndIf

fori=1tomRs.pagesize

%>
<tr>
<tdwidth=64%bgcolor=#FFFFFFclass=STYLE1><%=mrs(name)%></td>
<tdwidth=36%bgcolor=#FFFFFFclass=STYLE1><%=mrs(pass)%></td>
</tr><%
mRs.movenext
IfmRs.eofthenexitfor
next
mRs.close
SetmRs=nothing
%>
<tr>
<tdcolspan=2bgcolor=#CCCCCC>
<spanclass=STYLE1>
<%
callPageControl(iCount,maxpage,page)
SubPageControl(iCount,pagecount,page)

生成上一页下一页链接
Dimquery,a,x,temp
action=
query=Split(Request.ServerVariables(QUERY_STRING),&)
ForEachxInquery
a=Split(x,=)
IfStrComp(a(0),page,vbTextCompare)<>0Then
temp=temp&a(0)&=&a(1)&&
EndIf
Next
Response.Write(<tableborder=0cellpadding=3style=border-collapse:collapsewidth=100%align=center>)
Response.Write(<formmethod=getonsubmit=document.location=&action&?&temp&Page=+this.page.value;returnfalse;><tr>)
Response.Write(<tdalign=centerbgcolor=#FFFFFF>)
Ifpage<=1then
Response.Write(首页)
Response.Write(上一页)
Else
Response.Write(<ahref=&action&?&temp&Page=1>首页</a>)
Response.Write(<ahref=&action&?&temp&Page=&(Page-1)&>上一页</a>)
EndIf
Ifpage>=pagecountthen
Response.Write(下一页)
Response.Write(尾页)
Else
Response.Write(<ahref=&action&?&temp&Page=&(Page+1)&>下一页</a>)
Response.Write(<ahref=&action&?&temp&Page=&pagecount&>尾页</a>)
EndIf
Response.Write(页次:&page&/&pageCount&页)
Response.Write(共有&iCount&条留言)
Response.Write(转到&<inputtyep=textname=pagemaxlength=5value=&page&style=font-size:12px;border:1pxsolid#CCCCCC;width:23px;>&页<inputtype=submitstyle=font-size:9ptvalue=GOstyle=font-size:12px;border:1pxsolid#CCCCCC;width:23px;>)
Response.Write(</td></tr></form>)
Response.Write(</table>)

EndSub
%>
</span></td>
</tr>
</table>

<spanclass=STYLE1>
</p>

</form>
</body>
</html>


评论


亲,登录后才可以留言!