user2202527
user2202527

Reputation:

How to set many reports.rdlc into one report viewer ( In Coding )

I got a problem in my vb Project, as from subject its clear that I have a problem in specifying many reports in one report viewer in one form. It's difficult to create many forms and adding report viewer in each form.

I have more than 100 reports.rdlc and want to show it in one report viewer by choosing multiple options in combobox or different criterias.

Upvotes: 0

Views: 10231

Answers (3)

pagejaws
pagejaws

Reputation: 1

Just as tezzo said,

    ReportViewer1.LocalReport.DataSources.Clear()
    ReportViewer1.LocalReport.ReportPath = "Report2.rdlc"
    ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WebForms.ReportDataSource("DataSet1", CType(d1, DataTable)))
    ReportViewer1.LocalReport.SetParameters(New Microsoft.Reporting.WebForms.ReportParameter("ReportCriteria", criteria))
    ReportViewer1.LocalReport.SetParameters(New Microsoft.Reporting.WebForms.ReportParameter("FileDate", fileDateString))
    ReportViewer1.Visible = True
    ReportViewer1.DataBind()

Changing the localreport reportpath to a different reportname is all you really need.

Upvotes: 0

Alex
Alex

Reputation: 4948

If you want the same form window to appear each time you change report in your combobox, just create a new instance of that form every time you go to generate the .rdlc report.


Button1 Click

When you click this button, it will create two reports. One report will be generated from the method YourFirstReport() and the other from YourSecondReport(). Both using the same ReportViewer1 control from the same form using a new instance of rv.

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    'Create instance "rv" of your report viewer form
    Dim rv As New frmReportViewer
    rv.YourFirstReport()

    rv = New frmReportViewer
    rv.YourSecondReport()
End Sub

rv.YourFirstReport()

Public Sub YourFirstReport()
    ReportViewer1.LocalReport.ReportEmbeddedResource = "YourProject.YourFirstReportName"
    '...
    'And so on..
End Sub

rv.YourSecondReport()

Public Sub YourSecondReport()
    ReportViewer1.LocalReport.ReportEmbeddedResource = "YourProject.YourSecondReportName"
    '...
    'And so on..
End Sub

Take my example here, the square in red has a button that generates my frmReportViewer every time I click on it. The green circles demonstrate my reports that pop up. Both these report utilize the same form. Multiple reports in 1 form

Upvotes: 3

tezzo
tezzo

Reputation: 11115

You can create a single ReportViewer and set his property at runtime:

  • path to rldc file: .LocalReport.ReportPath
  • report datasources: .LocalReport.DataSources
  • report parameters: .LocalReport.SetParameters
  • other property: for example .LocalReport.EnableExternalImages

Then you can .RefreshReport().

Upvotes: 0

Related Questions