DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Print Datagrid Contents Only

11.23.2006
| 1332 views |
  • submit to reddit
        // Print a DataGrid Alone from an ASP.NET Web Page
// Posted on http://www.devx.com/tips/Tip/27626 by Jaya Nehru Kumar

<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 />