How to take a print of a grid view (with paging enabled) on button click ?

I have a gridview on which there is paging enabled (in my case 10 records per page).There is a button on the same page which when clicked should print those 10 records (on the grid.)
How should we be doing this ?
Here is the design of my grid:

<asp:GridView ID="grdvDetails" AutoGenerateColumns="true" runat="server"
                          AllowPaging="True" AllowSorting="true">
                                <RowStyle CssClass="gridContent" />
                                <HeaderStyle CssClass="gridHeader" />
                                <PagerStyle CssClass="content01" />                              

and the button on which the print command should be fired:
<asp:ImageButton ID="imgbtnPrintSummary" runat="server" ImageUrl="~/images/button_print_grid.gif"
                                   width="105" height="20" OnClick="imgbtnPrintSummary_Click"  />

Thanks in advance for any help
Cheers !
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


Sending to the the certain printer using some kind of printer WebControl would not be possible. Although such controls do exist, that is not really handy because your applicatiosn is running on the server and end-user is located somewhere else on the internet-intranet. But with javascript you can initiate print function of the IE or some other browser. End-user will be able to choose the printer he wants and print the page. You can do that as below:
<title>JavaScript Sample by tgreer</title>
<script type="text/javascript">
  function printMe()
     document.getElementById("printed").value = "YES";

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
if you want to print only grid part you can play little bit with styles...
use something like this:
<link rel="stylesheet"   type="text/css"  media="print" href="print.css" />

@media print
    BODY { font-size: 10pt }
 @media screen
    BODY { font-size: 12pt }
suruchijainAuthor Commented:
Hi hamidovt:,

Thanks for your reply
I have found the exact solution for my query through a friend's help: her it is:

<script language="javascript" type="text/javascript">
function CallPrint(strid)
 var prtContent = document.getElementById(strid);
 var WinPrint ='','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
// prtContent.innerHTML=strOldOne;
<!--for the grid: --> enclose in the <div/>  tag
  <div id="divPrint">
                            <asp:GridView ID="grdvSummary" runat="server" AllowPaging="True" AllowSorting="True"
                                OnPageIndexChanged="grdvSummary_PageIndexChanged" PageIndex="0" OnPageIndexChanging="grdvSummary_PageIndexChanging">                                
the button from which we have fire the command:
<asp:ImageButton ID="imgbtnPrintSummary" runat="server" ImageUrl="~/images/button_print_grid.gif"
                                   width="105" height="20" OnClientClick="javascript:CallPrint('divPrint');"/>
: this is a lttlel similar to your 1st solution, but I wanted a print of only the grid.
Thanks again for ur help

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

You can do what ever you want, but I dont like solutions with so many javascript. Probably you did not understand waht I mean. I have not sent you 2 solutions, I the second post was just an additional explanation about printing only grid part. I was assuming your know stylesheets ....

@media says on which media  stylesheet will be applied. So if your define following style and mark the sections you do not want to be printed. The main advantage of that is that also "Print" from the file menu will print only the grid part and the "Print Preview" will display only the part that will be actually printed.

@media print
    .NONprintable { display: none;}

This is very handy for marking such parts as navigation and header as non printable...

As for printing part,  window.print(); will print the page. So you can add it where ever you want...


If this solves your problem, could you please accept my solution??

I object closing the solution with points refund. I have made suggestion that would solve the problem and even after have come short on other issues (outside of the original question)  I have given additional explanation an provided solution.

I request my first comment to be accepted as a solution.

Force accepted.
Experts Exchange Moderator
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.