Thank you for the reply. I managed to get rid of the Java error on the page. All I did is to change the case of the Function CallPrint(ByVal strid) to function CallPrint(ByVal strid) and the error was away but could get it to print. It opens the new windows
but no data in the window. Take a look and see if you get the same result.
Life is a game of Chess, every step and move has to be planned well in advance, a piece lost takes long to recover. But, there is a difference that game of life NEVER ends in a DRAW.
I have implemented the same solution in my application. Everything is fine. But one problem is there. When Grid has more number of columns, then it's not handling to print all the columns. CHopping the columns to print area. Atleast it should print in the
next page. Which is not happening. I think all of you should have the same problem. Please check it and help me, if you know the solution.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
'javascript event handler for printing gridview control
Button1.Attributes.Add("onClick", "CallPrint('divPrint')")
End Sub
If it solves your issue please mark this posting as "Answered".
function Button1_onclick() {
//open new window set the height and width =0,set windows position at bottom
var a = window.open ('','','left =' + screen.width + ',top=' + screen.height + ',width=0,height=0,toolbar=0,scrollbars=0,status=0');
//write gridview data into newly open window
a.document.write(document.getElementById('innerData').innerHTML);
a.document.close();
a.focus();
//call print
a.print();
a.close();
return false;
}
SilverMecer
Member
15 Points
5 Posts
Re: How to print the data from the GridView
Jan 04, 2006 12:33 PM|LINK
Thank you for the reply. I managed to get rid of the Java error on the page. All I did is to change the case of the Function CallPrint(ByVal strid) to function CallPrint(ByVal strid) and the error was away but could get it to print. It opens the new windows but no data in the window. Take a look and see if you get the same result.
kvenr99
Member
2 Points
1 Post
Re: How to print the data from the GridView
Jan 26, 2009 03:16 PM|LINK
I have implemented the same solution in my application. Everything is fine. But one problem is there. When Grid has more number of columns, then it's not handling to print all the columns. CHopping the columns to print area. Atleast it should print in the next page. Which is not happening. I think all of you should have the same problem. Please check it and help me, if you know the solution.
marx.net
Participant
1068 Points
224 Posts
Re: How to print the data from the GridView
Jan 26, 2009 03:39 PM|LINK
Follow and Try this way
in Aspx
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Test</title>
<script type="text/javascript" >
function CallPrint(strid)
{
var prtContent = document.getElementById(strid);
var WinPrint = window.open('print.htm','PrintWindow','letf=0,top=0,width=800%,height=600,toolbar=1,scrollbars=1,status=1');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="divPrint">
<asp:GridView ID="GridView1" runat="server" BorderColor="#6600CC" BorderStyle="Solid" BorderWidth="1px" CellPadding="1" ForeColor="#333333"
Width="825px" EmptyDataText="No record found" Height="137px" Visible="False" AllowSorting="True" ShowFooter="True" >
</asp:GridView>
</div>
<asp:Button ID="Button1" runat="server" Text="Print" Visible="False" Width="159px" />
</form>
</body>
</html>
In Vb file Page load event
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
'javascript event handler for printing gridview control
Button1.Attributes.Add("onClick", "CallPrint('divPrint')")
End Sub
Thanks.
vikas shukla
Member
2 Points
1 Post
Re: How to print the data from the GridView
Jun 03, 2009 12:31 PM|LINK
hi sir
i also want to know that how it will be possible to take print out of paging in grid view.
kindly give me your suggestions,
Thanks
nareshkumar_...
Member
8 Points
4 Posts
Re: How to print the data from the GridView
May 21, 2010 11:40 AM|LINK
Hi Guys,
Try out this,It really works good for printing a grid view
<script language="javascript" type="text/javascript">
function Button1_onclick() {
//open new window set the height and width =0,set windows position at bottom
var a = window.open ('','','left =' + screen.width + ',top=' + screen.height + ',width=0,height=0,toolbar=0,scrollbars=0,status=0');
//write gridview data into newly open window
a.document.write(document.getElementById('innerData').innerHTML);
a.document.close();
a.focus();
//call print
a.print();
a.close();
return false;
}
</script>
Use this script ant call the gridview like this
<div id="innerData">
<asp:GridView ID="grdReport" runat="server" AutoGenerateColumns="false">
</GridView
</div>