2011-12-07 94 views
0

我正在從一個SQL數據庫獲取其數據的網頁上工作。我想打破記錄,以便當它到達第三行時,它將打破到另一個頁面。 我有一個javacript爲了它打破頁面。但是,這些記錄顯示在表中。而且我不知道如何放置在代碼中。任何建議? 謝謝。在經典的ASP頁面中斷

<style>div.break {page-break-before:always}</style>

Sub DisplayRecords() 
    Do until registerRS.eof 
     counter=counter+1 
     if counter=41 then 
      counter=0 
      counter=counter+1 
     end if 
     r = r + 1 
     If r = 1 then 
      Response.write "<tr>" 
     End if 
     %> 
    <td> 
    <%=registerRS.Fields("SchoolId")%> <br /> 
    Class: <%=registerRS.Fields("class")%><br /> 
    </td> 
     <% 
     If r = 2 then 
      Response.write "</tr>" 
     End if 

     If r = 3 then r = 1 
     registerRS.movenext 
    loop 
    registerRS.close 
    set registerRS=nothing 
End sub 
+3

的說明上標註...不要使用 'ASP'。它是含糊不清和貶值的。請將來使用asp-classic標籤。 –

回答

2

您應該能夠到樣式應用到錶行。從查看你的代碼我假設你想每行顯示3條記錄,每三行分頁一次。如果這樣你就可以做到以下幾點:

CSS

tr.break {page-break-before:always;} 

ASP

Sub DisplayRecords() 
    rowCount = 0 
    Do until registerRS.eof 
    counter=counter+1 
    if counter=41 then 
    counter=0 
    counter=counter+1 
    end if 
    r = r + 1 
    If r = 1 then 
     if rowCount < 3 then 
      Response.write "<tr>" 
      rowCount = rowCount + 1 
     else 
      Response.write "<tr class='break'>" 
      rowCount = 0 
    End if 
    %> 
<td> 
<%=registerRS.Fields("SchoolId")%> <br /> 
Class: <%=registerRS.Fields("class")%><br />      
</td>   


    <% 
    If r = 2 then 
      Response.write "</tr>" 
     End if 

     If r = 3 then r = 1 
    registerRS.movenext 
    loop 
    registerRS.close 
    set registerRS=nothing 
    End sub 
    %> 

This fiddle展示了運行中的代碼。打印this page以查看分頁符的操作。

然而

最優雅的方式來做到這一點是使用CSS3 nth Child Selector。缺點是缺乏來自舊版瀏覽器和IE的瀏覽器支持。

你會使用這樣的:

tr:nth-child(3n +4) {page-break-before:always;} 
/*3n says select every third row with + 4 being the row to start from*/ 

this fiddle和打印預覽this one

+0

嗨,我試過了代碼。它沒有給出錯誤,但由於某種原因,它不會在第三排中斷。 – JohnDoe4136

+0

@ JohnDoe4136可以提供一個呈現給頁面的代碼示例。謝謝。 –