您的位置:首页 > 编程语言 > ASP

对于ASP下的分页问题

2015-10-08 09:30 441 查看
对于分页网上有不少说法,而最终我还是喜欢要用如下的方式进行。在这个基础上还是需要思考将代码固化与独立的问题,以便减少引用时的重复性!!
<body  bgcolor="#4B9385">
<div id="dv1">
<form method="post">
<table width="1048" height="25" border="0">
<tr>
<th width="286"><strong class="t">申请单号</strong>  <input type="text" name="vNid" /></th>
<th width="287"><strong class="t">收款方</strong>
  <input type="text" name="v1" /></th>
<th width="213"><strong class="t">摘要</strong>
  <input type="text" name="v3" /></th>
<th width="244"><strong class="t">申请人</strong>
  <input type="text" name="v5" /></th>
</tr>
<tr>
  <th><strong class="t">备注</strong>    <input type="text" name="v4"/></th>
  <th><input type="checkbox" value="1" name="p1"/>
    <strong class="t">是否审核</strong>
    <input type="checkbox" value="1" name="p2"/>
    <strong class="t">是否审批</strong>
    <input type="checkbox" value="1" name="p3"/>
    <strong class="t">是否支付</strong></th>
  <th><input type="submit" value="查询" />
  </th>
  <th> </th>
  </tr>
</table>
</form>
</div>
<%
dim sW
set Rbx=server.CreateObject("adodb.recordset")
if request.form("vNid")<>"" then
	sW=" (rtrim(vNid) like '%"+trim(request.form("vNid"))+"%')"
else
	sW=" (1=1)"
end if
if request.form("v1")<>"" then
	sW=sW & " and (rtrim(v1) like '%"+trim(request.form("v1"))+"%')"
end if
if request.form("v3")<>"" then
	sW=sW & " and (rtrim(v3) like '%"+trim(request.form("v3"))+"%')"
end if
if request.form("v4")<>"" then
	sW=sW & " and (rtrim(v4) like '%"+trim(request.form("v4"))+"%')"
end if

if request.form("v5")<>"" then
	sW=sW & " and (rtrim(vx1) like '%"+trim(request.form("v5"))+"%')"
end if

if request.form("p1")=1 then
	sW=sW & " and (isnull(vx2,N'')<>N'')"
end if

if request.form("p2")=1 then
	sW=sW & " and (isnull(vx3,N'')<>N'')"
end if

if request.form("p3")=1 then
	sW=sW & " and (isnull(vx4,N'')<>N'')"
end if
PgSz=20 '设定开关,指定每一页所显示的帖子数目,默认为20帖一页
Set RS = Server.CreateObject("ADODB.RecordSet")
sql = "SELECT * FROM bxv  where " + SW
'查询所有帖子,并按帖子的ID倒序排列
RS.open sql,cN,1,1
If RS.RecordCount=0 then
     response.write "<P><center>对不起,数据库中没有相关信息!</center></P>"
  else
    RS.PageSize = Cint(PgSz) '设定PageSize属性的值
    Total=INT(RS.recordcount / PgSz * -1)*-1 '计算可显示页面的总数
    PageNo=Request("pageno")
    if PageNo="" Then
       PageNo = 1
        else
       PageNo=PageNo+1
       PageNo=PageNo-1
        end if
    ScrollAction = Request("ScrollAction")
    if ScrollAction = " 上一页 " Then
    PageNo=PageNo-1
    end if    
    if ScrollAction = " 下一页 " Then
    PageNo=PageNo+1
    end if
    if PageNo <1 Then 
    PageNo = 1
    end if
    n=1
    RS.AbsolutePage = PageNo
    Response.Write "<CENTER>"
    position=RS.PageSize*PageNo
    pagebegin=position-RS.PageSize+1
    if position <RS.RecordCount then
      pagend=position
    else  
      pagend= RS.RecordCount
        end if  
%>
<TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0 BGCOLOR=#FFFFFF color=#F00 class="tx">
<TR class="t2">
<TD><B>序号</B></TD><TD><B>申请单号</B></TD>
<TD><B>收款方</B></TD><TD><B>款项</B></TD>
<TD><B>摘要</B></TD><TD><B>备注</B></TD>
<TD><B>申请情况</B></TD><TD><B>审核情况</B></TD>
<TD><B>审批情况</B></TD><TD><B>支持情况</B></TD>
<TR>
<%
   Do while not (RS is nothing) 
    RowCount = RS.PageSize
    Do While Not RS.EOF and rowcount > 0 
     If n=1 then
         Response.Write "<TR BGCOLOR=#FFFFFF>"
     ELSE
         Response.Write "<TR BGCOLOR=#EEEEEE>"
     End If
     n=1-n %>
     <TD><span style="font-size:9pt"><% =RS("id")%></span></td> 
     <TD><span style="font-size:9pt"><% =RS("vNid")%></span> </TD>
     <TD><span style="font-size:9pt"><% =RS("v1")%></span> </td>
     <TD><span style="font-size:9pt"><% =RS("v2")%></span> </td>
     <TD><span style="font-size:9pt"><% =RS("v3")%></span> </td>
     <TD><span style="font-size:9pt"><% =RS("v4")%></span> </td>
     <TD><span style="font-size:9pt"><% =RS("vx1")%></span> </td>     
     <TD><span style="font-size:9pt"><% =RS("vx2")%></span> </td>     
     <TD><span style="font-size:9pt"><% =RS("vx3")%></span> </td>     
     <TD><span style="font-size:9pt"><% =RS("vx4")%></span> </td>     
    </TR>
    <%
    RowCount = RowCount - 1
    RS.MoveNext
    Loop
    set RS = RS.NextRecordSet
    Loop
      cN.Close
      set rs = nothing
      set cN = nothing
%>
</TABLE>
<FORM method="get" action="#">
<INPUT TYPE="HIDDEN" NAME="pageno" VALUE="<% =PageNo %>">
<% 
  if PageNo > 1 Then 
    response.write "<INPUT TYPE=SUBMIT NAME='ScrollAction' VALUE=' 上一页 '>"
  end if 
  if RowCount = 0 and PageNo <>Total then 
    response.write "<INPUT TYPE=SUBMIT NAME='ScrollAction' VALUE=' 下一页 '>"
  end if     
End if
%>
</FORM>
</body>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: