printing gridview

G

Guest

Hello Everyone,

I am trying to print a gridview. I have a print button on my aspx page.
Below is the javascript code

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();
// prtContent.innerHTML=strOldOne;
}

<asp:Button ID="btnPrint" runat="server" Text="Print the Grid"
OnClick="btnPrint_Click" Style="position: static" />

Inside the aspx.cs page, i have
btnPrint.Attributes["onclick"] = "javascript:CallPrint('print_Grid');";

and my gridview is inside the <div> tag

<div id="print_Grid">
gridview - that needed to be printed

</div>

I have two questions:

1) I can print the grid view but not all the columns are coming in the
printout. Last 10 columns of the aspx screen are cutoff from the printout. Is
it possible to printout and see all the columns. I tried landscpae view, but
still all the columns are not coming in the print out.
2) can I get the header of the gridview in every printout.

Please let me know if it possible

Thanks.
 
G

Guest

Vinki,

Printing a gridView from an ASP .net page can become a nightmare. I would
rather let the user export the grid into excel so he can configure the output
using a powerful Office product like Ms Excel.

A fast way to export a grid view to Excel (no extra code from your side
needed, just use this free source code):

http://www.dotnetjohn.com/articles.aspx?articleid=231

Good luck,
Braulio

PS: More info about ASP .net and Excel Export:

http://www.tipsdotnet.com/ArticleBlog.aspx?KWID=51&Area=Excel&PageIndex=0

More info about ASP .net Gridview:

http://www.tipsdotnet.com/ArticleBlog.aspx?KWID=3&Area=GridView&PageIndex=0

/// ------------------------------
/// Braulio Diez
///
/// http://www.tipsdotnet.com
/// ------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top