当前位置:编程学习 > asp >>

ASP应用范例-分页_代码部分

答案:<%

dim Conn,RS,sqlStr,PageSize,RowCount,TotalPages,PageNo,Position,PageBegin,PageEnd

set Conn= Server.CreateObject("ADODB.Connection")

set RS = Server.CreateObject("ADODB.RecordSet")

Conn.open "provider=sqloledb;data source=127.0.0.1;user id=sa;password=;initial catalog=zjydata"

sqlStr="select * from Items order by iID"

RS.open sqlStr,Conn,1,1

PageSize=10

If RS.RecordCount=0 then

%>

<TABLE WIDTH=100% BORDER=0 CELLPADDING=1 CELLSPACING=1 style='font-size:9pt'>

<TR bgcolor=#003366 height=20px>

<TD align=center><font color=#FFFFFF>商品代码</font></TD>

<TD align=center><font color=#FFFFFF>商品名称</font></TD>

<TD align=center><font color=#FFFFFF>型号规格</font></TD>

<TD align=center><font color=#FFFFFF>计量单位</font></TD>

<TD align=center><font color=#FFFFFF>参考进价</font></TD>

<TD align=center><font color=#FFFFFF>参考售价</font></TD>

<TD align=center><font color=#FFFFFF>备注</font>

</TR>

<TR height=20px>

<TD align=center>没有任何商品信息!</TD>

<TR>

</TABLE>

<%

else

RS.PageSize = Cint(PageSize)

TotalPages=RS.PageCount

PageNo=Request.QueryString("PageNo")

if PageNo="" or PageNo<1 Then

PageNo = 1

end if

RS.AbsolutePage = PageNo

Position=RS.PageSize*PageNo

PageBegin=Position-RS.PageSize+1

if Position <RS.RecordCount then

PageEnd=Position

else

PageEnd= RS.RecordCount

end if

%>

<TABLE WIDTH=100% BORDER=0 CELLPADDING=1 CELLSPACING=1 style='font-size:9pt'>

<TR>

<TD width=20%>

<%

Response.Write "页:"& PageNo &" / "& TotalPages &" | 记录:"& PageBegin & " - " & PageEnd & " / " &RS.RecordCount

%>

</TD>

<TD align=right>

<%

if PageNo > 1 Then

response.write "<a href=>
end if

if TotalPages > 1 and cint(PageNo) <> cint(TotalPages) then

response.write "<a href=>
end if

%>

</TD>

</TR>

<TR bgcolor=#003366 height=20px>

<TD align=center width=20%><font color=#FFFFFF>商品代码</font></TD>

<TD align=center width=30%><font color=#FFFFFF>商品名称</font></TD>

<TD align=center width=8%><font color=#FFFFFF>型号规格</font></TD>

<TD align=center width=8%><font color=#FFFFFF>计量单位</font></TD>

<TD align=center width=8%><font color=#FFFFFF>参考进价</font></TD>

<TD align=center width=8%><font color=#FFFFFF>参考售价</font></TD>

<TD align=center width=18%><font color=#FFFFFF>备注</font></TR>

<%

RowCount = RS.PageSize

dim color1,color2

color1="#dddddd"

color2="#eeeeee"

Do While Not RS.EOF and RowCount > 0

Response.Write "<TR height=20px bgcolor="

%>

<%

if RowCount mod 2=0 then:response.write color1 else:response.write color2

%>

<%

Response.Write ">"

%>

<TD><span><a href=>
<TD><span><% =RS("vName")%></span></td>

<TD><span><% =RS("vSpec")%></span></TD>

<TD><span><% =RS("vUnit")%></span></td>

<TD><span><% =RS("fInPrice")%></span></td>

<TD><span><% =RS("fOutPrice")%></span></TD>

<TD><span><% =RS("vDescription")%></span></td>

</TR>

<%

RowCount = RowCount - 1

RS.MoveNext

Loop

Conn.Close

set RS = nothing

set Conn = nothing

%>

<TR bgcolor=#003366 height=20px>

<TD align=center width=20%><font color=#FFFFFF>商品代码</font></TD>

<TD align=center width=30%><font color=#FFFFFF>商品名称</font></TD>

<TD align=center width=8%><font color=#FFFFFF>型号规格</font></TD>

<TD align=center width=8%><font color=#FFFFFF>计量单位</font></TD>

<TD align=center width=8%><font color=#FFFFFF>参考进价</font></TD>

<TD align=center width=8%><font color=#FFFFFF>参考售价</font></TD>

<TD align=center width=18%><font color=#FFFFFF>备注</font>

</TR>

<TR>

<TD>

<%

For i=1 to TotalPages

if CInt(PageNo) = CInt(i) then

response.write "["&i&"]"

上一个:ASP应用范例-分页_执行示意图
下一个:提示:制作Online HTMLEditor必备的知识

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,