Description:-
In this example we explain that how to show print
button in Report Viewer. I also face that problem like report viewer print
button is not showing in fire fox and chrome browser by default it will show in
Internet Explorer. Or print button not visible in report viewer for mozila fire
fox and chrome browser. So how to display print button in report viewer
that display in all browser like browser comp ability code for report viewer
print button so it will work for the all the browser.
Code.aspx:-
<%@
Control Language="C#" AutoEventWireup="true" CodeBehind="ReportUCL.ascx.cs" Inherits="SolusoftDashboard.ReportUCL"
%>
<%@
Register Assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb"
%>
<script type="text/javascript"
src="Scripts/jquery-1.4.4.min.js"></script>
<style type="text/css">
.reportViewerCtrl
{
}
</style>
<script type="text/javascript"
language="javascript">
$(document).ready(function
() {
if
($.browser.mozilla || $.browser.webkit) {
try
{
showPrintButton();
}
catch
(e) { alert(e); }
}
});
function
showPrintButton() {
var
table = $("table[title='Refresh']");
var
parentTable = $(table).parents('table');
var
parentDiv = $(parentTable).parents('div').parents('div').first();
parentDiv.append('<select
name="ctl00$ContentPlaceHolder1$reportViewer$rptViewer$ctl01$ctl03$ctl00"
title="Zoom" id="ctl00_ContentPlaceHolder1_reportViewer_rptViewer_ctl01_ctl03_ctl00"
style="font-family: Verdana; font-size: 8pt; onclick="PrintReport();
onChange="showzoom();"> <OPTION value=PageWidth>Page
Width</OPTION> <OPTION value=FullPage>Whole Page</OPTION>
<OPTION value=500>500%</OPTION> <OPTION value=200>200%</OPTION>
<OPTION value=150>150%</OPTION> <OPTION selected
value=100>100%</OPTION> <OPTION value=75>75%</OPTION>
<OPTION value=50>50%</OPTION> <OPTION
value=25>25%</OPTION> <OPTION value=10>10%</OPTION>');
parentDiv.append('<input name="ctl00$ContentPlaceHolder1$reportViewer$rptViewer$ctl01$ctl04$ctl00"
title="Find Text"
id="ctl00_ContentPlaceHolder1_reportViewer_rptViewer_ctl01_ctl04_ctl00"
style="font-family: Verdana; font-size: 8pt;" onkeypress="keyprs();"
onpropertychange="propertychnge();" type="text"
size="10" maxLength="255"/>');
parentDiv.append('<a title="Find"
id="ctl00_ContentPlaceHolder1_reportViewer_rptViewer_ctl01_ctl04_ctl01"
style="font-family: Verdana; color: gray; font-size: 8pt; text-decoration:
none;" href="#" onclick="Find();"
onmouseover="mouseover();" onmouseout="mouseout();" Controller="[object
Object]">Find</a>');
parentDiv.append('<a title="Find Next"
id="ctl00_ContentPlaceHolder1_reportViewer_rptViewer_ctl01_ctl04_ctl03"
style="font-family: Verdana; color: gray; font-size: 8pt; text-decoration:
none;" onmouseover="this.Controller.OnLinkHover();"
onmouseout="this.Controller.OnLinkNormal();"
onclick="Next();" href="#" Controller="[object
Object]"> | Next</a>');
parentDiv.append('<input type="image"
style="border-width: 0px; padding:
3px;margin-top:2px; height:16px; width: 16px;" alt="Print"
src="/Reserved.ReportViewerWebControl.axd?OpType=Resource&Version=9.0.30729.1&Name=Microsoft.Reporting.WebForms.Icons.Print.gif";title="Print"
onclick="PrintReport();">');
}
function
Next() {
document.getElementById('ctl00_ContentPlaceHolder1_reportViewer_rptViewer').ClientController.HandleSearchNext();
return false;
}
function
mouseout() {
this.Controller.OnLinkNormal();
}
function
mouseover() {
this.Controller.OnLinkHover();
}
function
keyprs() {
if
(event.keyCode == 10 || event.keyCode == 13) {
document.getElementById('ctl00_ContentPlaceHolder1_reportViewer_rptViewer').ClientController.ActionHandler('Search', document.getElementById('ctl00_ContentPlaceHolder1_reportViewer_rptViewer_ctl01_ctl04_ctl00').value);
; return false;
}
}
function
propertychnge() {
if
(event.propertyName == 'value') {
document.getElementById('ctl00_ContentPlaceHolder1_reportViewer_rptViewer_ctl01_ctl04_ctl01').Controller.SetViewerLinkActive(this.value != null
&& this.value != '');
document.getElementById('ctl00_ContentPlaceHolder1_reportViewer_rptViewer_ctl01_ctl04_ctl03').Controller.SetViewerLinkActive(false);
}
}
function
Find() {
document.getElementById('ctl00_ContentPlaceHolder1_reportViewer_rptViewer').ClientController.ActionHandler('Search', document.getElementById('ctl00_ContentPlaceHolder1_reportViewer_rptViewer_ctl01_ctl04_ctl00').value);
return false;
//
document.getElementById('ctl00_ContentPlaceHolder1_reportViewer_rptViewer_ctl01_ctl04_ctl01').Controller
= new ReportViewerLink("ctl00_ContentPlaceHolder1_reportViewer_rptViewer_ctl01_ctl04_ctl01",
false, "", "", "#3366CC", "Gray",
"#FF3300");
}
function
clicks() {
document.getElementById('ctl00_ContentPlaceHolder1_reportViewer_rptViewer').ClientController.ActionHandler('Search', document.getElementById('ctl00_ContentPlaceHolder1_reportViewer_rptViewer_ctl01_ctl04_ctl00').value);
return false;
}
//zoom effect
function
showzoom() {
document.getElementById('ctl00_ContentPlaceHolder1_reportViewer_rptViewer').ClientController.SetZoom(event.srcElement.value);
}
// Print
Report function
function
PrintReport() {
//Code
for adding HTML content to report viwer
var
headstr = "<html><head><title></title></head><body>";
//End of
body tag
var
footstr = "</body></html>";
//This
the main content to get the all the html content inside the report viewer
control
//"ReportViewer1_ctl10"
is the main div inside the report viewer
//controls
who helds all the tables and divs where our report contents or data is
available
var
newstr = $("#ctl00_ContentPlaceHolder1_reportViewer_rptViewer").html();
//open
blank html for printing
var
popupWin = window.open('', '_blank');
//paste
data of printing in blank html page
popupWin.document.write(headstr +
newstr + footstr);
//print
the page and see is what you see is what you get
popupWin.print();
return false;
};
$(document).ready(function
() {
if
($.browser.webkit) {
$(".reportViewerCtrl
table").css('display', 'inline-block');
}
});
$(DocReady);
function
DocReady() {
$('option[value
= PDF]').remove();
}
</script>
<table width="100%"
cellpadding="0"
cellspacing="0"
style="margin: 0 0 0 0">
<tr id="trMessage" runat="server" visible="false">
<td style="vertical-align: top" class="messageContent">
<asp:Label ID="lblMessage" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr id="trReport" runat="server">
<td id="tdReportviewer" runat="server" style="vertical-align: top;" height="900">
<rsweb:ReportViewer ID="rptViewer" CssClass="reportViewerCtrl" runat="server" OnDrillthrough="rptViewer_Drillthrough"
Width="100%" OnReportError="rptViewer_ReportError" OnDocumentMapNavigation="rptViewer_DocumentMapNavigation"
OnPageNavigation="rptViewer_PageNavigation" OnSearch="rptViewer_Search"
OnSort="rptViewer_Sort"
OnToggle="rptViewer_Toggle" ZoomMode="Percent" SizeToReportContent="false"
AsyncRendering="true"
ShowBackButton="false">
</rsweb:ReportViewer>
</td>
</tr>
</table>
does not work
ReplyDelete