2013年12月1日 星期日

[asp] Table如何分頁



 <%
   sqlstr = "SELECT top 100 * FROM WebReport inner join org on report_dept = org_id order by report_projectyear desc, report_id desc"
   Set Rs = Server.CreateObject("ADODB.Recordset")
   Rs.open sqlstr,conn, 1, 3
   i = 0

 

   PageMax = 3       '一頁幾筆 
   Page = Server.HtmlEncode(Request("Page"))


   if Rs.EOF Then
      TotalPages = 1
      Page = 1
     'count = 0
   Else
      Rs.PageSize = PageMax        '一頁幾筆 
      TotalPages = Rs.PageCount '共幾頁
     'count = Rs.RecordCount '共幾筆
 
      If CInt(Page) < 1 Then Page = 1
      If CInt(Page) > Cint(TotalPages) Then Page = TotalPages
      Rs.AbsolutePage = Page '當前頁數
   End If
%>




          <table summary="功能區塊攔位" width="90%"  border="0" cellspacing="0" cellpadding="4">
            <tr valign="middle" bgcolor="#999999">
              <th width="10%" align="center" class="f02"><strong>序號</strong></td>
              <th align="center" class="f02"><strong>計畫名稱</strong></td>
             
              <th width="30%" align="center" class="f02"><strong>計畫期程(年)</strong></td>
         
            </tr>
          </table>

<%
For i = 1 to Rs.PageSize '利用for next 循環依次讀出當前頁的記錄 
  If rs.EOF then 
    Exit For 
  End if  
 
  iNo = PageMax * (page-1) + i  '序號

%>

               
           
       
            <table summary="功能區塊攔位" width="90%"  border="0" cellspacing="0" cellpadding="4">
              <tr bgcolor="#FFFFFF">
                <td width="10%" align="center" class="f04">  <%=iNo%> </td>
                <td align="left"><img src="../catch/icon03.gif" alt="委託研究報告選項圖片" width="7" height="7" align="absmiddle"> <a href="/APFile/big5/report/files/<%=Rs("report_file1")%>" target="_blank" title="<%=Rs("report_file1_desc")%>"><%=Rs("report_topic")%></a></td>
                <td width="30%" align="center" class="f04">                
                <% If Instr(Rs("report_projectyear"), "-") Then
    If Left(Split(Rs("report_projectyear"),"-")(0),1) = "0" Then
        Response.Write(Right(Split(Rs("report_projectyear"),"-")(0),2) & "-")
Else
        Response.Write(Split(Rs("report_projectyear"),"-")(0) & "-")
End if


    If Left(Split(Rs("report_projectyear"),"-")(1),1) = "0" Then
        Response.Write(Right(Split(Rs("report_projectyear"),"-")(1),2))
Else
        Response.Write(Split(Rs("report_projectyear"),"-")(1))
End if
  Else
 
    If Left( Rs("report_projectyear"),1) = "0" Then
        Response.Write(Right( Rs("report_projectyear"),2))
Else
        Response.Write( Rs("report_projectyear"))
End if
  End if

   
%>
             
             
             
                </td>
              </tr>
 <%
 
  rs.MoveNext 
next 
%>
            </table>
         
        <table summary="功能區塊攔位" width="100%"  border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="right"><a href="index.asp?page=1">第一頁</a><%if page > 1 then %> | <a href="index.asp?page=<%=Page - 1%>">上一頁</a><%end if%><%if TotalPages >= Page + 1 then%> | <a href="index.asp?page=<%=Page + 1%>">下一頁</a><%end if%> | <a href="index.asp?page=<%=TotalPages%>">最末頁</a>
           第<%=Page%>頁 / 共<%=TotalPages%>頁 </td>
          </tr>
        </table>   
     

<%
   Rs.close
   set Rs = nothing
%>



參考:
http://big5.webasp.net/article/17/16145.htm

沒有留言:

張貼留言