Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: ASP.NET
Expertise: Beginner
Mar 22, 2005

Print a DataGrid Alone from an ASP.NET Web Page

Ever wanted to print a DataGrid alone from an ASP.NET Web page? Put an <asp:DataGrid> tag inside the tag does the trick. Here are the steps involved:
  1. Enclose the <asp:datagrid></asp:datagrid> tag inside the <div></div> tag.
  2. Write a JavaScript function which takes care of printing the content from <div> tag.
Here's an example:

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

<div id="divPrint">
<asp:datagrid>
.....
.....
.....
</asp:datagrid>
</div>
<asp:button ID="btnPrint" onClick="javascript:CallPrint('divPrint');" Runat=Server />
Jaya Nehru Kumar
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap