Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
script:window.print() to print the data from gridview
but It displays entire data on the web page in the paper

Is it possible to print gridview data only?
Posted
Updated 15-Jun-12 2:45am
v3
Comments
ZurdoDev 15-Jun-12 9:01am    
There are some nice free jquery plug-ins that will print a given element. So, you could wrap it in a div and use the plugin.

1 solution

Either you can write your print related code in code behind and then inject it into the page:
How to Print in ASP.NET 2.0[^]

OR using JavaScript directly on the page itself, like:
JavaScript
function CallPrint()
{
  var printContent = document.getElementById('<%= pnlToPrint.ClientID %>');
  var printWindow = window.open("", "Print Panel", ‘left=50000,top=50000,width=0,height=0′);
  printWindow.document.write(prtContent.innerHTML);
  printWindow.document.close();
  printWindow.focus();
  printWindow.print();
  printWindow.close();
}

HTML
<asp: Panel runat="server" id="pnlToPrint" >
  <table>
    <tr>
      <td>
         Your data
      </td>
    </tr>
  </table>
</asp: Panel>

<input type="button" value="Print"  onclick="CallPrint();" />

Above code prints just the content inside the panel - can be a grid or even just a label.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900