I checked your example and attempted to implement. My gridview is also in a panel so I have the panel name as part of the javascript function. I have a javascript alert popup so I know it gets to the function from the ASP button. I then see a basic browser
window appear but it is completely balnk. Maybe you can advise and review the code I enetered below.
gogginl
Member
79 Points
264 Posts
Grid Print - What is the best way to print the data? Should port the grid to a AJAX grid and prin...
Nov 30, 2012 03:45 PM|LINK
I need to print the data in my Gridview which is running server side (standard gridview control bound to SQL datasource.
What is the best method to print the data?
I am looking to add a print button on the web page but have read this cannot be done using the gridview.
Is it better to use AJAX grid - meaning I would store the data in a datagrid and bind it to ajax gridview and print from
this?
Also I need to print each row of data as a label.
Thx
niksv
Contributor
5953 Points
1119 Posts
Re: Grid Print - What is the best way to print the data? Should port the grid to a AJAX grid and ...
Dec 01, 2012 11:56 AM|LINK
//JS function printGridView() { var html = document.getElementById('Panel1').innerHTML; var printwin = window.open('about:blank', 'printwin'); printwin.document.write(html); printwin.focus(); printwin.print(); printwin.close(); } //ASPX <input type="button" value="Print" onclick="printGridView()" /> <br /> <asp:Panel runat="server" ID="Panel1"> <asp:GridView ID="GridView1" runat="server" /> </asp:Panel>gogginl
Member
79 Points
264 Posts
Re: Grid Print - What is the best way to print the data? Should port the grid to a AJAX grid and ...
Dec 03, 2012 06:53 PM|LINK
Nice but looking for something that I can print specific cells in the gridview. Is that possible?
aderegil
Contributor
3318 Points
593 Posts
Re: Grid Print - What is the best way to print the data? Should port the grid to a AJAX grid and ...
Dec 03, 2012 09:40 PM|LINK
The solution provided will work for you.
You may need to adjust it a little bit to remove the cells that you do not need.
But please provide more info about what cells you need printed and what cells you need to skip.
vijay_myl
Contributor
5070 Points
1068 Posts
Re: Grid Print - What is the best way to print the data? Should port the grid to a AJAX grid and ...
Dec 04, 2012 02:19 AM|LINK
Hi..
please refer the below link to print the grd view data ........
http://www.dotnetcode.in/2012/04/take-print-only-gridview-data-in-aspnet.html
My .NET blog
Submit Article
manjuby
Participant
1131 Points
251 Posts
Re: Grid Print - What is the best way to print the data? Should port the grid to a AJAX grid and ...
Dec 04, 2012 03:47 AM|LINK
Use this Javascript function
function PrintGridData() {
var prtGrid = document.getElementById('<%=gvUserInfo.ClientID %>');
prtGrid.border = 0;
var prtwin = window.open('', 'PrintGridViewData', 'left=100,top=100,width=1000,height=1000,tollbar=0,scrollbars=1,status=0,resizable=1');
prtwin.document.write(prtGrid.outerHTML);
prtwin.document.close();
prtwin.focus();
prtwin.print();
prtwin.close();
}
include this line just below the gridview definition
<input type="button" id="btnPrint" value="Print" onclick="PrintGridData()" />
gogginl
Member
79 Points
264 Posts
Re: Grid Print - What is the best way to print the data? Should port the grid to a AJAX grid and ...
Dec 04, 2012 08:29 PM|LINK
I checked your example and attempted to implement. My gridview is also in a panel so I have the panel name as part of the javascript function. I have a javascript alert popup so I know it gets to the function from the ASP button. I then see a basic browser window appear but it is completely balnk. Maybe you can advise and review the code I enetered below.
<asp:Button ID="btnPrint" runat="server" Text="Print" Width="174px" OnClientClick="myPrint();"/>
<script type="text/javascript" >
function myPrint(PanelGridview) {
alert("You made to print bud!");
var printContent = document.getElementById("PanelGridview");
var WindowUrl = 'about:blank';
var WindowName = 'Print';
var WinPrint = window.open(WindowUrl, WindowName, 'left=300, top=300, right=500, bottom=500, width=1000, height=500');
WinPrint.document.write('<' + 'html' + '><head></head><' + 'body style="background:none !important"' + '>');
WinPrint.document.write(printContent.innerHTML);
WinPrint.document.write('</body></html>');
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.Close();
}
</script>
gogginl
Member
79 Points
264 Posts
Re: Grid Print - What is the best way to print the data? Should port the grid to a AJAX grid and ...
Dec 04, 2012 08:32 PM|LINK
Simple,
If I have 5 cells (a,b,c,d,e) and I want to only print cells b, d and e because column A is the edit column and dont want that to print.
aderegil
Contributor
3318 Points
593 Posts
Re: Grid Print - What is the best way to print the data? Should port the grid to a AJAX grid and ...
Dec 06, 2012 02:42 PM|LINK
If your Grid is coming from a DataTable you can remove the A and C columns from the datatable before sending to print.
You may need to create a print-only version of your grid to do that.