[英]How to print each gridview in a separate page using JavaScript
I have 3 grid views in my page. 我的页面上有3个网格视图。 I'm using javascript to print all of them.
我正在使用javascript打印所有这些文件。
Now I want to Print each gridview in a separate page. 现在,我想在单独的页面中打印每个gridview。
Below is my JavaScript Code. 以下是我的JavaScript代码。
<script type = "text/javascript">
function PrintPanel() {
var panel = document.getElementById("<%=pnlContents.ClientID %>");
var printWindow = window.open('', '', 'height=400,width=800');
printWindow.document.write('<html><head><title></title>');
printWindow.document.write('</head><body >');
printWindow.document.write(panel.innerHTML);
printWindow.document.write('</body></html>');
printWindow.document.close();
setTimeout(function () {
printWindow.print();
}, 500);
return false;
}
</script>
I use CSS to do this for me: css: 我使用CSS为我做到这一点:CSS:
.pageBreak {
position: relative;
page-break-after: always
}
html: 的HTML:
<div id="gridView1" class="pageBreak">
<!-- your grid view -->
</div>
in your case it might be something like: 在您的情况下,可能类似于:
<script type = "text/javascript">
function PrintPanel() {
var panel = document.getElementById("<%=pnlContents.ClientID %>");
var printWindow = window.open('', '', 'height=400,width=800');
printWindow.document.write('<html><head><title></title>');
printWindow.document.write('</head><body>');
printWindow.document.write('<div class="pagereak"');
printWindow.document.write(panel.innerHTML);
printWindow.document.write('</div></body></html>');
printWindow.document.close();
setTimeout(function () {
printWindow.print();
}, 500);
return false;
}
</script>
though in your case the pageBreak class shoul;d be in the innerHTML I guess 虽然在您的情况下pageBreak类应该;应该在innerHTML中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.