Last post Aug 21, 2008 11:18 AM by grahamlower
Jun 19, 2008 11:44 AM|xysoulyx|LINK
Hi guys.. i have seen some arcticles on printing forms and not many addressed the issue of a form having scrolls bars and printing the data and fields of all in the form with the bottom part of the form. Is there a way to achieve that ?
Jun 22, 2008 01:28 AM|grahamlower|LINK
When I want to have a great deal of control of what prints out I use the ReportViewer control and report designer that comes with Visual Studios (you can also download the viewer for Visual Web Developer 2005:
http://www.microsoft.com/downloads/details.aspx?familyid=8a166cac-758d-45c8-b637-dd7726e61367&displaylang=en). Because the report viewer can create a PDF document, you have a great deal of control over how the document.
You create a datatable thatholds all of the dynamic data, then load it in code, and use that for the report viewer datasource. If you just drop the report viewer control on the page and wire it up simply, the user will see a copy of the data and have the
option to export to either of Excel of PDF (there are "hacks" to get other formats, if you want to serach for them).
If you want to go the extra mile, you can just use the report view in code and server up a PDF (or whatever) without having to mess with the UI of the report viewer. Yor code would look something lihe the following:
Dim report As LocalReport =
report.ReportPath = Server.MapPath("~/" + rdlcPath)
Dim rptDS As ReportDataSource =
Dim Ps As New System.Collections.Generic.List(Of ReportParameter)
Select Case reportSelect
Using ta As New StudentInspectorTableAdapters.SIFInformationTableAdapter
rptDS = New ReportDataSource("neededDataSource", ta.GetData())
Dim deviceInfo As String = _
"<DeviceInfo>" & _
" <OutputFormat>PDF</OutputFormat>" & _
" <PageWidth>11in</PageWidth>" & _
" <PageHeight>8.5in</PageHeight>" & _
" <MarginTop>1in</MarginTop>" & _
" <MarginLeft>1in</MarginLeft>" & _
" <MarginRight>1in</MarginRight>" & _
" <MarginBottom>1in</MarginBottom>" & _
Dim Warnings As Warning() =
Dim streams As String() =
Dim mimeType As String =
Nothing, encoding As String = Nothing, fileNameExtension
As String = Nothing
Dim renederedBytes As Byte() = report.Render(Request("m"), deviceInfo, mimeType, encoding, fileNameExtension, streams, Warnings)
Response.ContentType = mimeType
"attachment; filename=Report." + fileNameExtension)
Some of the variables above need to be defined in your code (e.g. rdlcPath), but what it's looking for shouldn't be cryptic. This code could go anywhere from Load to Prerender, just remember to buffer the output and do not flush any data (you can not change,
or add, headers after you start flushing data... which would be problematic).
Aug 19, 2008 06:28 AM|mansaah|LINK
Hi I am trying to use your code but unfortunately, I’ve got some error:
Aug 21, 2008 11:18 AM|grahamlower|LINK
First off, this code was not meant to be a copy and paste solution. It was an example that would provide a rough guide to how to solve the problem. Before attempting to do anything with this code you should setup a "drag and drop" report; After you have
designed and saved you report, drag and drop a ReportViewer on to your page, then set it's source to your new report.
1) You will need to change this to your datasource. In my case, I was using a TableAdapter.
2) This was specific to the context from which I pulled the code (this was foundation for this code serving multiple datasources). I'd avoid the select case and just use the "NormalReport" branch.
3) Parameters are for data that generally not database driven. A ReportDataSource is used to pass in database type data in.