I have htmltable which dynamically generated. I want to print this table. which consist lot of pages. when I used window.print() its printing into 7, 8 pages. but my problem is I need Header and footer on each page (A4 size). how can Set header and footer to each page. I am using asp.net with C#.
I put header and footer on .aspx page but problem is that data is binding dynamic when I print then print goes multiple pages (ie 4 or 5 pages depend on data). So header come on first page and footer on l开发者_StackOverflow社区ast page I need header and footer on each page
Please provide me any suggestion or alternate way to do this task.
I tried this solution its working.
<style type="text/css">
@media print {
thead { display: table-header-group; }
tfoot { display: table-footer-group; }
}
@media screen {
thead { display: block; }
tfoot { display: block; }
}
</style>
<body>
<table>
<thead><tr><td>Your header goes here</td></tr></thead>
<tbody>
<tr><td>
Page body in here -- as long as it needs to be
</td></tr>
</tbody>
<tfoot><tr><td>Your footer goes here</td></tr></tfoot>
</table>
</body>
If you absolutely have to have a header/footer, you will need to insert a page break into every X table cell, where X is the number of cells you want to appear on each page. The page break will have to duplicate your header and footer.
So, your table will look like this:
HEADER
<table>
<tr><td>Cell Data</td></tr>
<!-- A bunch of rows -->
<tr><td>Cell Data</td></tr>
<tr>
<td>
Cell Data
<div class="pagebreak">
<div>FOOTER</div>
<!-- Print page will break here -->
<div class="header">HEADER</div>
</div>
</td>
</tr>
<tr><td>Cell Data</td></tr>
<!-- A bunch of rows -->
<tr><td>Cell Data</td></tr>
<tr>
<td>
Cell Data
<div class="pagebreak">
<div>FOOTER</div>
<!-- Print page will break here -->
<div class="header">HEADER</div>
</div>
</td>
</tr>
</table>
FOOTER
And then add the following style to your page:
<style type="text/css">
@media all
{
.pagebreak { display:none; }
}
@media print
{
.pagebreak { display:block; }
.pagebreak div.header { display:block;page-break-before:always; }
}
</style>
Edit: I updated the HTML to (hopefully) make it more clear what needed to be done.
You create a master page in which you define header area and footer area and take one div in each area and access that div in code behind page and put your generated html in the div like this way--div.InnerHtml=="you string containing html table"
精彩评论