suruchijain
asked on
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" />
</asp:GridView>
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="imgbtnPrintSummar y_Click" />
Thanks in advance for any help
Cheers !
How should we be doing this ?
Here is the design of my grid:
<asp:GridView ID="grdvDetails" AutoGenerateColumns="true"
AllowPaging="True" AllowSorting="true">
<RowStyle CssClass="gridContent" />
<HeaderStyle CssClass="gridHeader" />
<PagerStyle CssClass="content01" />
</asp:GridView>
and the button on which the print command should be fired:
<asp:ImageButton ID="imgbtnPrintSummary" runat="server" ImageUrl="~/images/button_
width="105" height="20" OnClick="imgbtnPrintSummar
Thanks in advance for any help
Cheers !
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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(st rid);
var WinPrint = window.open('','','letf=0, top=0,widt h=1,height =1,toolbar =0,scrollb ars=0,stat us=0');
WinPrint.document.write(pr tContent.i nnerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
// prtContent.innerHTML=strOl dOne;
}
</script>
<!--for the grid: --> enclose in the <div/> tag
<div id="divPrint">
<asp:GridView ID="grdvSummary" runat="server" AllowPaging="True" AllowSorting="True"
OnPageIndexChanged="grdvSu mmary_Page IndexChang ed" PageIndex="0" OnPageIndexChanging="grdvS ummary_Pag eIndexChan ging">
</asp:GridView>
</div>
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
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(st
var WinPrint = window.open('','','letf=0,
WinPrint.document.write(pr
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
// prtContent.innerHTML=strOl
}
</script>
<!--for the grid: --> enclose in the <div/> tag
<div id="divPrint">
<asp:GridView ID="grdvSummary" runat="server" AllowPaging="True" AllowSorting="True"
OnPageIndexChanged="grdvSu
</asp:GridView>
</div>
the button from which we have fire the command:
<asp:ImageButton ID="imgbtnPrintSummary" runat="server" ImageUrl="~/images/button_
width="105" height="20" OnClientClick="javascript:
: this is a lttlel similar to your 1st solution, but I wanted a print of only the grid.
Thanks again for ur help
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...
@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...
Hi,
If this solves your problem, could you please accept my solution??
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.
I request my first comment to be accepted as a solution.
Force accepted.
kb
Experts Exchange Moderator
kb
Experts Exchange Moderator
use something like this:
<link rel="stylesheet" type="text/css" media="print" href="print.css" />
or
@media print
{
BODY { font-size: 10pt }
}
@media screen
{
BODY { font-size: 12pt }
}