asp学习

慢慢成长,知识是靠积累的,经验最重要!

导航

asp分页代码(最实用的)


平时常用的分页代码!放上去备忘啊,每次用都要找,老是记不住,现在copy一下,改改参数就可以了!
分页代码一
<%
page=request("page")
count=rs.recordcount
if count<1 then
response.write "<br />
<center>数据库中没有资料!</center>"
response.end
end if
'分页处理
const size = 12
rs.pagesize=size
totlepage=int(count/size)
if (count mod size)>0 then totlepage=totlepage+1
if len(page)>0 and isnumeric(page) then
page =int(page)
else
if page="" then page=1
if page>totlepage then
page =totlepage
else
page=1
end if
end if
if page>totlepage then page=totlepage
if page<1 then page=1
position=rs.PageSize*Page
pagebegin=position-rs.PageSize+1
rs.absoluteposition=pagebegin
%>
<table cellspacing="0" cellpadding="0" width="550" align="center" border="0">
    <tbody>
        <tr>
            <td>
            <div align="center">
            <table cellspacing="2" cellpadding="3" width="100%" border="0">
                <tbody>
                    <tr bgcolor="#c0c0c0">
                        <td width="10%" bgcolor="#c0c0c0" height="25">
                        <div align="center">ID</div>
                        </td>
                        <td width="67%">
                        <div align="center">新闻标题</div>
                        </td>
                        <td width="10%">
                        <div align="center">操作</div>
                        </td>
                        <td width="13%">
                        <div align="center">操作</div>
                        </td>
                    </tr>
                    <%i=0%><%do while not rs.eof and i<size%>
                    <tr bgcolor="#e3e3e3">
                        <td height="22">
                        <div align="center"><%=rs("id")%></div>
                        </td>
                        <td><%=rs("title")%></td>
                        <td bgcolor="#e3e3e3">
                        <div align="center"><A href="admin_news.asp?id=<%=rs(" id?)%>&amp;update=update"&gt;修改</a></div>
                        </td>
                        <td>
                        <div align="center"><A href="admin_News.asp?id=<%=rs(" id?)%>&amp;delete=1"&gt;删除</a></div>
                        </td>
                    </tr>
                    <% rs.movenext()
                    i=i+1
                    loop %>
                    <tr align="center" bgcolor="#c0c0c0">
                        <td colspan="4" height="25">
                        <table cellspacing="0" cellpadding="0" width="100%" border="0">
                            <tbody>
                                <tr>
                                    <td class="black30" align="right" width="57%">当前第<%=page%>页     <%if page>1 then%><A href="admin_news.asp?page=<%=page-1%>">上一页</a> <%else if page=1 then%><a>上一页</a> <%end if%><%end if%><%if page<totlepage then%><A href="admin_news.asp?page=<%=page+1%>">下一页</a> <%else if page=totlepage then%><a>下一页</a> <%end if%><%end if%></td>
                                    <td align="center" width="43%">共<%=totlepage%>页<%=count%>条新闻 </td>
                                </tr>
                            </tbody>
                        </table>
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 分页代码2
                        <table cellspacing="0" cellpadding="0" width="93%" align="center" border="0">
                            <%
                            If rs.RecordCount >0 Then
                            rs.PageSize=20
                            rs.AbsolutePage=1
                            nextpage=2
                            lastpage=1
                            nowpage=1
                            if Request("page")<>"" then
                            rs.AbsolutePage =request("page")
                            nowpage=request("page")
                            nextpage=request("page")+1
                            lastpage=request("page")-1
                            end if
                            rowcount=rs.PageSize
                            endpage=rs.PageCount
                            while not rs.EOF  and rowcount>0
                            %>
                            <tbody>
                                <tr>
                                    <td width="3%"><img height="12" alt="" src="images/tb.gif" width="13" /></td>
                                    <td class="blue121" width="86%" height="30"><A class=blue121 onclick="window.open('gonggao_tc.asp?NewsID=<%=rs(" href="#" NewsID?)%>','','width=570,height=480,scrollbars=yes')"&gt;<%=rs("title")%></a></td>
                                    <td class="00629C_11" valign="middle" align="left" width="11%"><%=Formatdatetime(rs("AddDate"),2)%></td>
                                </tr>
                                <%
                                rs.MoveNext
                                rowcount=rowcount-1
                                wend
                                if nextpage>rs.PageCount then
                                nextpage=rs.PageCount
                                end if
                                if lastpage<1 then
                                lastpage=1
                                end if
                                End if
                                %>
                            </tbody>
                        </table>
                        <table cellspacing="0" cellpadding="0" width="90%" align="center" border="0">
                            <tbody>
                                <tr>
                                    <td class="black6666661" valign="middle" align="right" height="40"><a class="black12" href="gonggao.asp?Page=1">首页</a> <A class=black12 href="gonggao.asp?Page=<%=lastpage%>">上一页</a> <A class=black12 href="gonggao.asp?Page=<%=nextpage%>">下一页</a> <A class=black12 href="gonggao.asp?Page=<%=rs.PageCount%>">尾页</a>  <span class="black12">页次:</span><span class="black12"><strong><font color="red"><%=nowpage%></font></strong>/<strong><font color="red"><%=endpage%></font></strong>页</span>     <span class="black12">转到: <script language="JavaScript">
      function jump(m)
      {
      window.location.href=m
      }
      </script><select onchange="jump(this.value)" name="jump">
                                    <option value=""  selected></option>
                                    <OPTION value="gonggao.asp?page=<%=i%>"></option>
                                    </select> 页</span> </td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                </tbody>
                <div></div>
            </tr>
        </tbody>
    </table>
    </div>
</tr>
</tbody>
</table>

posted on 2007-11-22 15:13  laopu  阅读(629)  评论(0编辑  收藏  举报