Visual Studio .NET - reportviewer open command in print preview
Asked By David on 02-Apr-12 04:04 PM
Hi
Is it possible to put code into a rdlc report using reportviewer so that it opens the report in print preview mode from a button instead of having to click preview on tool bar when report is open.
I am using Visual Studio 2008
Thanks
David
[)ia6l0 iii replied to David on 02-Apr-12 09:19 PM
If it is a web version, you could call the Microsoft.Reporting.WebFormsClient.ReportViewer.invokePrintDialog Method from the client side.
Add a button :
<input id="ButtonPrintReport" type="button" value="Print Report" onclick="PrintReport();"/>
And add a script like below:
<script language="javascript">
function PrintReport()
{
var reportViewer = $find("ReportViewer1");
var reportArea = reportViewer.get_reportAreaContentType();
if (reportArea == Microsoft.Reporting.WebFormsClient.ReportAreaContent.ReportPage)
{
reportViewer.invokePrintDialog();
}
}
</script>
Otherwise, you will have to use the CreateStreamCallback function and print the report programmatically without viewing it. Here is a MSDN walkthrough on this.
http://msdn.microsoft.com/en-us/library/ms252091.aspx
Hope this helps.