Printing a datagrid

Posted: August 19, 2010 in ASP.NET

Hi,

Here I would like to share the code to print a datagrid in ASP.NET

Put the given code in tag

function CallPrint(strid) {
var prtContent = document.getElementById(strid);
var WinPrint = window.open('', '', 'letf=0,top=0,width=1,height=1,t oolbar=0,scrollbars=0,status=0');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
//prtContent.innerHTML = strOldOne;
}

Put your datagrid in a

tag. Here I use a div named “divPrint”.

Put this code in your print button

OnClientClick="javascript:CallPrint('divPrint');"

or

OnClick="javascript:CallPrint('divPrint');"

:) Coding !!

Advertisement
Comments
  1. [...] The busiest day of the year was August 19th with 28 views. The most popular post that day was Printing a datagrid. [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s