How to Print Datagrid in ASP.Net


To print only the content of the datagrid control, you need to encapsulate it with div element.

Example:

  1. <script type="text/javascript" language="javascript">// <![CDATA[
  2. function PrintDataGrid(elementname) {
  3. var oDiv = document.getElementById(elementname);
  4. var oprint_window = window.open('', '', 'letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
  5.  
  6. oprint_window.document.write(oDiv.innerHTML);
  7. oprint_window.document.close();
  8. oprint_window.focus();
  9. oprint_window.print();
  10. oprint_window.close();
  11. }
  12. // ]]></script>

or

  1. <input id="Button1" onclick="javascript:PrintDataGrid('DatagridData')" type="button" value="button" />

,

  1. No comments yet.
(will not be published)
Submit Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Subscribe to comments feed
  1. No trackbacks yet.

SetPageWidth