简体   繁体   English

打破经典的ASP页面

[英]Break in classic ASP page

I'm working on a webpage where it gets its data from a SQL database. 我正在开发一个从SQL数据库获取数据的网页。 And I want to break the records so that when it reaches the third row, it will break to another page. 我想要打破记录,以便当它到达第三行时,它将分解到另一页。 I have a javacript in order for it to break page. 我有一个javacript,以便它打破页面。 However, this records are displayed in a table. 但是,此记录显示在表格中。 And I don't know how to place in the code. 而且我不知道如何放入代码中。 Any suggestion? 有什么建议吗? Thanks. 谢谢。

<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

You should be able to apply that style to a table row. 您应该能够将该样式应用于表格行。 From looking at your code I'm assuming you want to display 3 records per row, with a page break every three rows. 从查看你的代码我假设你想要每行显示3条记录,每三行都有一个分页符。 If so you can do the following: 如果是这样,您可以执行以下操作:

CSS CSS

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

ASP 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 shows the code in action. 这个小提琴显示了代码的实际效果。 Print this page to see the page break in action. 打印此页面以查看分页符。

However 然而

The most elegant way to do this is to use the CSS3 nth Child Selector . 最优雅的方法是使用CSS3第n个子选择器 The downside is lack of browser support from older browsers and IE. 缺点是缺乏旧浏览器和IE浏览器的支持。

You would use something like: 你会使用类似的东西:

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

See this fiddle and print preview this one 看到这个小提琴和打印预览这一个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM