@ Mr.zaid thanks for the reply but i am unable to find definition for strOldOne. and this code does not enforce page break
@Mr.Zhang thank you too sir, but both of them doesnot gives me a solution my bad luck, [:(]
Any way i just tweaked the javascript code and added an nested table in the for loop to print the header row, the only one issue is the left and right border of the tr of the parent table breaks and it looks like a slit on either side, but i told my client
to live with that , if ever i found a solution i will make it good. guys can you think of something.
sansknowledg...
Member
28 Points
72 Posts
page break issue in grid view printing
Feb 19, 2009 06:57 AM|LINK
hi,
i am having a gridview, i am printing it with a javascript the javascript code is
WinPrint.document.write('<table border="1" cellspacing="0" cellpadding="4" style="font-size:10pt;border-collapse:collapse;border-bottom:1px solid;" align="center">'); var rowcount=0; var pagebreakcount=0; for (var loop=0;loop < prtContent.rows.length;loop++) { pagebreakcount++; if (pagebreakcount==25) { alert('page break'); pagebreakcount=0; WinPrint.document.write('<tr style="page-break-before:always;display:block;">'); //alert(prtContent.rows[0].cells.length); WinPrint.document.write(prtContent.rows[0].innerHTML); WinPrint.document.write('</tr>'); } //else{ WinPrint.document.write('<tr>');//} if (loop==0){ prtContent.rows[loop].cells[0].innerText= "Sl.No"; } if (prtContent.rows[loop].cells[0].innerText== "Select") {prtContent.rows[loop].cells[0].innerText= rowcount++; } WinPrint.document.write(prtContent.rows[loop].innerHTML); WinPrint.document.write('</tr>'); } WinPrint.document.write('</table>');gridview tables javava script page break
yasserzaid
Star
13991 Points
2597 Posts
Re: page break issue in grid view printing
Feb 21, 2009 01:17 PM|LINK
Hi
try this example:
<html>
<head runat="server">
<script language="javascript">
function CallPrint( strid )
{
var prtContent = document.getElementById( strid );
var WinPrint = window.open('', '', 'left=0,top=0,width=900,height=600,toolbar=1,scrollbars=1,status=0');
WinPrint.document.write( prtContent.innerHTML );
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
prtContent.innerHTML=strOldOne;
}
</script>
</head>
<body>
<asp:Button ID="PrintButton" runat="server" Style="position: static" Text="Print" />
<div id=print_Grid>
// your Gridview here
</div>
</body>
</html>
in code behind :-
PrintButton.Attributes["onclick"] = "javascript:CallPrint('print_Grid');";
Good Luck
Lance Zhang ...
All-Star
33091 Points
2361 Posts
Re: page break issue in grid view printing
Feb 24, 2009 05:40 AM|LINK
GridView Data Print In Asp.net 2.0
http://amitpatriwala.wordpress.com/2008/07/26/gridview-data-print-in-aspnet-20/
You can also check the following thread, which talks about the same thing:
How to print all the pages of the Gridview or Detailview
http://forums.asp.net/p/1034717/1427991.aspx
Thanks.
sansknowledg...
Member
28 Points
72 Posts
Re: page break issue in grid view printing
Feb 26, 2009 06:43 AM|LINK
@ Mr.zaid thanks for the reply but i am unable to find definition for strOldOne. and this code does not enforce page break
@Mr.Zhang thank you too sir, but both of them doesnot gives me a solution my bad luck, [:(]
Any way i just tweaked the javascript code and added an nested table in the for loop to print the header row, the only one issue is the left and right border of the tr of the parent table breaks and it looks like a slit on either side, but i told my client to live with that , if ever i found a solution i will make it good. guys can you think of something.
thanks and regards