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

asp数字分页函数 实际使用例子。

2011-04-14 18:41 197 查看
//调用例子。上面的函数我是封装在pagefunction.asp文件里面的   注明:在引入pagefunction.asp文件之前的也是可以封装成一个固定的文件里面。然后通过引入,调用对应的函数的。

 

//函数是代码重用的最基础的封装。练习多了,代码敲多了,很多基本的功能,都可以逐步封装成为自己的库代码

   <%
               
                  Const MaxPerPage=1
            dim totalPut  
            dim CurrentPage
            dim TotalPages
            dim j
            dim sql
            
            
            
            if Not isempty(SafeRequest("page",1)) then
              currentPage=Cint(SafeRequest("page",1))
            else
              currentPage=1
            end if
            
            i=0
            
            rs.open "select  * from acticle where categoryid=391 order by adddate desc",conn,1,1
   
           if rs.eof and rs.bof then
       
            rs.close
      
           response.write "<center>目前还没有新闻!</center>"
    
            else
              
              totalPut=rs.recordcount
              
              TotalPages=totalPut/MaxPerPage
              
              if (currentpage-1)*MaxPerPage>totalput then
               if (totalPut mod MaxPerPage)=0 then
                 currentpage= totalPut / MaxPerPage
               else
                 currentpage= totalPut / MaxPerPage + 1
               end if
                end if
               
                if currentPage=1 then
                   showContent
                   showpage totalput,MaxPerPage,"newslist.asp"
                else
                  if (currentPage-1)*MaxPerPage<totalPut then
                      rs.move  (currentPage-1)*MaxPerPage
                      dim bookmark
                      bookmark=rs.bookmark
                      showContent
                       showpage totalput,MaxPerPage,"newslist.asp"
                 else
                    currentPage=1
                      showContent
                      showpage totalput,MaxPerPage,"newslist.asp"
                end if
              end if
            end if  
              
            sub showContent
                      %>
                      <ul>
              <%
               do while not rs.eof
       
             i=i+1
        %>
                  <li><a href="news.asp?id=<% = rs("id") %>"><%=left(rs("name"),50)%></a><span><% = Year(rs("adddate")) %>.<% = Month(rs("adddate")) %>.<% = day(rs("adddate")) %></span><div class="clear"></div></li>
               
                 <% 
                  if i>=MaxPerPage then Exit Do
        
              rs.movenext
      
            loop
    
            
    
            rs.close
            %>
              </ul>
            <%
           end sub
          %>
         
           
           
        <!--#include file="pagesfunction.asp"-->
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  asp class file sql