Click here to Skip to main content
15,069,133 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
After getting my code to work to print a table from my asp.net c# web application, I noticed that the table is really big, it has alot of columns and rows and right now when I print, it squashes the whole table onto one page, is there anyway to split the table up to print on multiple pages as needed?

I am just so clueless as to how to achieve this?
This is the code I am using
JavaScript
function Print() {

        var prntData = document.getElementById('Table1');
        var mywindow = window.open('', 'printer', 'height=800,width=700,left=0,top=0,toolbar=0,scrollbar=0,status=0');
        mywindow.document.write('<html><head><title></title>');
        mywindow.document.write('</head><body style="direction:ltr;"><pre>');
        mywindow.document.write(prntData.outerHTML);
        mywindow.document.write('<link href="Reports/Print.css" rel="stylesheet" />');
        mywindow.document.write('</body></html>');
        mywindow.document.close();
        mywindow.print();
    }
Posted
Updated 21-Jan-14 1:19am
v2
Comments
rmksiva 21-Jan-14 6:56am
   
Can You Share the Code you used to print ?
Member 10395722 21-Jan-14 7:19am
   
I Added the code
Karthik_Mahalingam 21-Jan-14 8:29am
   
what do u mean by multiple pages ?
pagination ??
Member 10395722 21-Jan-14 8:56am
   
i mean that when the amount of columns reach page width it would print the rest of the columns on another page

OK, so you're using javascript, that's great. The best way I can think to control paging, is to actually pop up and print one page at a time.
   
v2
   
Comments
Christian Graus 21-Jan-14 19:21pm
   
Deleted my other comment, emitting pages and then printing them separately is probably the best solution.
IMHO, you should go for some reporting tool like the free option for ASP.NET that is shipped by MS called Local Reports (RDLC report files) that are displayed on an aspx page through the ReportViewer control. You could create a report with such table, then bind it through code to the data source, and let the ReportViewer to format it for printing purposes. You'll have more control on the printing process if you use a reporting tool.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900