如何使用css打印时在表行中设置分页符

如何使用css打印时在表行中设置分页符

本文介绍了如何使用css打印时在表行中设置分页符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有动态表行。这是使用foreach循环显示的。对于单页,仅打印表格内容。剩余内容未打印。如何使用css在表行中设置分页符?请帮帮我..

< div id =p>

< table width =100%border =1pxid =tbl >

<%foreach(Model.samplelist中的var项目){%>

< tr class =DisplayView1align =center>

< td class =DisplayView1>< div class =nobrk>

<%:item.slno%>< / div> ;< / td>

< td>< div class =nobrk>

<%:item.insdate%>< / DIV> < / td>

< td>< div class =nobrk>

<%:item.mon%>< / div> ; < / td>

< td>< div class =nobrk>

<%:item.paidate%>< / div> ;< / td>

< / tr>

<%}%>< / table>

< / div>

< input type =buttonname =Printvalue =Printonclick =print()/>





I have dynamic table rows. That is displayed using foreach loop. for a single page only table contents are printed. remaining contents are not printed. how to set page break in table rows using css? Please help me..
<div id="p">
<table width="100%" border="1px" id="tbl">
<% foreach (var item in Model.samplelist) {%>
<tr class="DisplayView1" align="center" >
<td class="DisplayView1" ><div class="nobrk">
<%: item.slno %></div></td>
<td ><div class="nobrk">
<%: item.insdate%></div> </td>
<td ><div class="nobrk">
<%: item.mon%></div> </td>
<td ><div class="nobrk">
<%: item.paidate%></div></td>
</tr>
<%}%></table>
</div>
<input type ="button" name="Print" value="Print" onclick="print()" />


<script type="text/javascript">
    function print() {
        var divToPrint = document.getElementById('p');
        var popupWin = window.open('', '_blank', '');
        popupWin.document.open();
        popupWin.document.write('<html><head>')
        popupWin.document.write('<style type="text/css">');
        popupWin.document.write('@media print{');
        popupWin.document.write('body{ background-color:#FFFFFF; background-image:none; color:#000000 }');
        popupWin.document.write('#ad{ display:none;}');
        popupWin.document.write('#leftbar{ display:none;}');
        popupWin.document.write('#contentarea{ width:100%;}');
        popupWin.document.write('}');
        popupWin.document.write('table');
        popupWin.document.write('{');
       popupWin.document.write('border: none;');
      //  popupWin.document.write('border-collapse:separate;');
        popupWin.document.write('}');
        popupWin.document.write('table td');
        popupWin.document.write('{');
        popupWin.document.write('padding: 2px;');
        popupWin.document.write('border: none;');
        popupWin.document.write('}');
        popupWin.document.write('table th');
        popupWin.document.write('{');
        popupWin.document.write('padding: 6px 5px;');
        popupWin.document.write('text-align: left;');
      //  popupWin.document.write('background-color: #e8eef4;');
      //  popupWin.document.write('border: none;');
        popupWin.document.write('}');


        popupWin.document.write('height: 100%;');
        popupWin.document.write('}');*/


        popupWin.document.write('</style>');
        popupWin.document.write('</head> <body onload="window.print()">' + divToPrint.innerHTML + '</html>');
        popupWin.document.close();

    }

                                         </script>

推荐答案


这篇关于如何使用css打印时在表行中设置分页符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 23:03