asp又一个分页的代码例子

2018-09-06 11:08

阅读:486

  一个分页代码例子
<%本程序文件名为:Pages.asp%>
<%包含ADO常量表文件,可从\ProgramFiles\CommonFiles\System\ADO目录下拷贝%>
<!--#IncludeFile=adovbs.inc-->
<%*建立数据库连接,这里是Oracle8.05数据库
conn.OpenProvider=msdaora.1;DataSource=YourSrcName;UserID=YourUserID;Password=YourPassword;

Setrs=Server.CreateObject(ADODB.Recordset)创建Recordset对象
rs.CursorLocation=adUseClient设定记录集指针属性
*设定一页内的记录总数,可根据需要进行调整
rs.PageSize=10

*设置查询语句
StrSQL=SelectID,姓名,住址,电话from通讯录OrderByID
rs.OpenStrSQL,conn,adOpenStatic,adLockReadOnly,adCmdText
%>
<HTML>
<HEAD>
<title>分页示例</title>
<scriptlanguage=javascript>
//点击[第一页]时响应:
functionPageFirst()
{
document.MyForm.CurrentPage.selectedIndex=0;
document.MyForm.CurrentPage.onchange();
}
//点击[上一页]时响应:
functionPagePrior()
{
document.MyForm.CurrentPage.selectedIndex--;
document.MyForm.CurrentPage.onchange();
}
//点击[下一页]时响应:
functionPageNext()
{
document.MyForm.CurrentPage.selectedIndex++;
document.MyForm.CurrentPage.onchange();
}
//点击[最后一页]时响应:
functionPageLast()
{
document.MyForm.CurrentPage.selectedIndex=document.MyForm.CurrentPage.length-1;
document.MyForm.CurrentPage.onchange();
}
//选择第?页时响应:
functionPageCurrent()
{//Pages.asp是本程序的文件名
document.MyForm.action=Pages.asp?Page=+(document.MyForm.CurrentPage.selectedIndex+1)
document.MyForm.submit();
}
</Script>
</HEAD>
<BODYbgcolor=#ffffcclink=#008000vlink=#008000alink=#FF0000>

<%IFrs.EofTHEN
Response.Write(<fontsize=2color=#000080>[数据库中没有记录!]</font>)
ELSE
指定当前页码
IfRequest(CurrentPage)=Then
rs.AbsolutePage=1
Else
rs.AbsolutePage=CLng(Request(CurrentPage))
EndIf

创建表单MyForm,方法为Get
Response.Write(<formmethod=Getname=MyForm>)
Response.Write(<palign=center><fontsize=2color=#008000>)
设置翻页超链接
ifrs.PageCount=1then
Response.Write([第一页][上一页][下一页][最后一页])
else
ifrs.AbsolutePage=1then
Response.Write([第一页][上一页])
Response.Write([<ahref=javascript:PageNext()>下一页</a>])
Response.Write([<ahref=javascript:PageLast()>最后一页</a>])
else
ifrs.AbsolutePage=rs.PageCountthen
Response.Write([<ahref=javascript:PageFirst()>第一页</a>])
Response.Write([<ahref=javascript:PagePrior()>上一页</a>])
Response.Write([下一页][最后一页])
else
Response.Write([<ahref=javascript:PageFirst()>第一页</a>])
Response.Write([<ahref=javascript:PagePrior()>上一页</a>])
Response.Write([<ahref=javascript:PageNext()>下一页</a>])
Response.Write([<ahref=javascript:PageLast()>最后一页</a>])
endif
endif
endif

创建下拉列表框,用于选择浏览页码
Response.Write(第<selectsize=1name=CurrentPageonchange=PageCurrent()>)
Fori=1tors.PageCount
ifrs.AbsolutePage=ithen
Response.Write(<optionselected>&i&</option>)当前页码
else
Response.Write(<option>&i&</option>)
endif
Next
Response.Write(</select>页/共&rs.PageCount&页共&rs.RecordCount&条记录</font><p>)
Response.Write(</form>)

创建表格,用于显示
Response.Write(<tablealign=centercellspacing=1cellpadding=1border=1)
Response.Write(bordercolor=#99CCFFbordercolordark=#b0e0e6bordercolorlight=#000066>)

Response.Write(<trbgcolor=#ccccffbordercolor=#000066>)

SetColumns=rs.Fields

显示表头
Fori=0toColumns.Count-1
Response.Write(<tdalign=centerwidth=200height=13>)
Next
Response.Write(</tr>)
显示内容
Fori=1tors.PageSize
Response.Write(<trbgcolor=#99ccffbordercolor=#000066>)
Forj=0toColumns.Count-1
Response.Write(<td><fontsize=2>&Columns(j)&</font></td>)
Next
Response.Write(</tr>)

rs.movenext
ifrs.EOFthenexitfor
Next

Response.Write(</table>)

ENDIF
%>
</BODY>
</HTML>


评论


亲,登录后才可以留言!