Click here to Skip to main content
15,890,381 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
Dear Experts,

How to Print a Asp.net Gridview.

I also need to print the Header logo (Complete Header) and also Gridview.

Please help . thank u.
Posted
Comments
RaviGupta7986 15-Jan-13 5:35am    
you would have got answer faster if you would have entered this text in google in place of code project :)

XML
You want to print only Gridview not entire page.

Solution is, put Gridview inside a Panel as below:

<asp: Panel runat="server" id="pnlToPrint" >
 <asp:GridView ID="gvReport" runat="server"........>
 ............
 ..............
 ............
 </asp:GridView>
</asp: Panel>
 <input type="button" value="Print"  onclick="CallPrint();" />

Now create a function as below:

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();
}
 
Share this answer
 
Comments
Member 12963969 23-Jan-17 13:17pm    
Thanks

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