Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 7th, 2009, 03:37 PM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default How to print a GridView data

Hi there i need to print a GridView data that is fed by sql 2005 db ,
is it posible to download the data from the grid?


thanks
__________________
bx
 
Old February 7th, 2009, 09:53 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default You could do something like...

put an html button on that page that says print and tie it to a javascript function then have that function open a new window and write the gridview to it then print?

<input id="prtButton" type="button" value="Print" onclick="CallPrint('<%= GridView1.ClientID %>');" />


Code:
<script language="javascript" type="text/javascript">
 function CallPrint( strid )
   {
    var prtContent = document.getElementById( strid );
    var WinPrint = window.open('', '', 'left=0,top=0,width=1050,height=600,toolbar=1,scrollbars=1,status=0');
    WinPrint.document.write( prtContent.innerHTML );
    WinPrint.document.close();
    WinPrint.focus();
    WinPrint.print();
    WinPrint.close();
   }
</script>
There's probably a better way to do this but this should work. what it's doing is on the onclick event of the prtButton it sends the client id of your gridview (which I assume is called GridView1) to the print function in javascript. the javascript passes the control to a new window then prints that window.

hope this is what you wanted....
__________________
Jason Hall

Follow me on Twitter @jhall2013
 
Old February 8th, 2009, 05:21 AM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

Hi thanks a lot that is exactly what i wanted i tryed it and it worked.
is this gonna print all the pages of the grid or just the one displayed ? and is there a way to pass the format from the grid to the print

thanks again
__________________
bx
 
Old February 8th, 2009, 08:26 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default Actually...

I believe if you have paging on then it will only print the visible page how ever if you want to print all the results from start to finish then you will have to disable the paging before you call the javascript function.
__________________
Jason Hall

Follow me on Twitter @jhall2013





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to print data across then down in RDLC report juzjess BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 August 25th, 2008 01:04 PM
Data Binding - Editing GridView Row Data desk_star BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 7 December 30th, 2007 11:07 AM
Print Data Grid SpringSummer ASP.NET 2.0 Basics 0 November 8th, 2007 11:52 PM
How to print from a dynamic gridview at runtime. VictorVictor ASP.NET 2.0 Professional 0 April 2nd, 2007 02:19 PM
Print data inside a div jdang67 CSS Cascading Style Sheets 1 August 11th, 2005 01:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.