Visual Studio .NET - ReportViewer does not show Print option.

Asked By imran khan on 12-Jun-13 12:33 PM
I am making Asp.net , C#(Visual Studio 2005) and SQl2000.

I am trying to  generate report using reportviewer. i managed to success in generating report but problem is reportviewer does not show print option. by default printoption is set to true i also set in design that option true as

 <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt"

        Height="400px" Style="left: 25px; position: absolute; top: 86px" Visible="False"

        Width="862px" ShowPrintButton ="true"  ShowBackButton="True" ShowFindControls="False">

        <LocalReport ReportPath="Report.rdlc">

 

 Still reportviewer does not show print option.

local reports - sundar k replied to imran khan on 10-Mar-07 05:46 AM

looks like you are running in local mode, e.g., local reports.  You have to be running remote reports for the reportviewer's print button to work.

as mentioned in the below link,

http://forums.asp.net/thread/1490236.aspx

ReportViewer show Print option.(via Coding) - raja k replied to imran khan on 31-Jul-08 04:04 AM

Hi Friends,

         Your can't Show the print option in asp.net ReportViewer. We Can Access the print through Coding only. See the below Coding you can easy to access the print button.

First you put one button in your print page ie(put top of the report viewer page)

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

'Dim myRPTForm As New RdlGenerator ' This would be your rdlc report for your labels

Dim report As LocalReport = New LocalReport()

' Public myPRT As Reporting

Dim myPRT As New Reporting

Dim m_rdl2 As System.IO.Stream

m_rdl2 = New System.IO.FileStream("D:\Reports\SampleHead1.rdl", IO.FileMode.Open, IO.FileAccess.Read)

' Set the physical path to your report rdlc file.

report.LoadReportDefinition(m_rdl2)

' report.ReportPath = "C:\data\reports\ActReq.rdlc"

' This next code binds my datasource to my report. I suspect you may be handling this differently.

Dim da5 As New SqlClient.SqlDataAdapter("select * from dbo.COLUMN_VALUE_VIEW", "Persist Security Info=False;User ID=;pwd=; Initial Catalog=; Data Source=")

da5.Fill(m_dataSet4)

report.DataSources.Add(New ReportDataSource("DataSet1", m_dataSet4.Tables(0)))

' This next code prepares the rdlc file for printing and calls the print function from the Reporting class file

myPRT.Export(report)

myPRT.m_currentPageIndex = 0

myPRT.Print()

End Sub

AFTER That Create one class file like   "Reporting.vb"

Imports System.IO

Imports System.Data

Imports System.Text

Imports System.Drawing.Imaging

Imports System.Drawing.Printing

Imports System.Collections.Generic

Imports Microsoft.Reporting.WinForms

Public Class Reporting

Implements IDisposable

Public m_currentPageIndex As Integer

Public m_streams As IList(Of Stream)

Public Function CreateStream(ByVal name As String, _

ByVal fileNameExtension As String, _

ByVal encoding As Encoding, ByVal mimeType As String, _

ByVal willSeek As Boolean) As Stream

Dim stream As Stream = _

New FileStream("D:\" + name + "." + fileNameExtension, FileMode.Create)

m_streams.Add(stream)

Return stream

End Function

Public Sub Export(ByVal report As LocalReport)

Try

Dim deviceInfo As String = _

"<DeviceInfo>" + _

" <OutputFormat>EMF</OutputFormat>" + _

" <PageWidth>8.5in</PageWidth>" + _

" <PageHeight>11in</PageHeight>" + _

" <MarginTop>0.25in</MarginTop>" + _

" <MarginLeft>0.25in</MarginLeft>" + _

" <MarginRight>0.25in</MarginRight>" + _

" <MarginBottom>0.25in</MarginBottom>" + _

"</DeviceInfo>"

Dim warnings() As Warning = Nothing

m_streams = New List(Of Stream)()

report.Render("Image", deviceInfo, AddressOf CreateStream, warnings)

Dim stream As Stream

For Each stream In m_streams

stream.Position = 0

Next

Catch ex As Exception

End Try

End Sub

Public Sub PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)

Dim pageImage As New Metafile(m_streams(m_currentPageIndex))

ev.Graphics.DrawImage(pageImage, ev.PageBounds)

m_currentPageIndex += 1

ev.HasMorePages = (m_currentPageIndex < m_streams.Count)

End Sub

Public Sub Print()

Const printerName As String = "Microsoft Office Document Image Writer"

If m_streams Is Nothing OrElse m_streams.Count = 0 Then

Return

End If

Dim printDoc As New PrintDocument()


' printDoc.PrinterSettings..PrinterName = printerName

If Not printDoc.PrinterSettings.IsValid Then

Dim msg As String = String.Format( _

"Can't find printer ""{0}"".", printerName)

Console.WriteLine(msg)

Return

End If

AddHandler printDoc.PrintPage, AddressOf PrintPage

printDoc.PrinterSettings.Duplex = Duplex.Horizontal

printDoc.Print()

End Sub

Public Overloads Sub Dispose() Implements IDisposable.Dispose

If Not (m_streams Is Nothing) Then

Dim stream As Stream

For Each stream In m_streams

stream.Close()

Next

m_streams = Nothing

End If

End Sub

End Class

        Compile and Check it..

Regards,

K. Raja

raja_online@hotmail.com