Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi every one when i try to 
drag and drop report viewer in form then report viewer are not display on form.
report view are show on the bottom of the page.


then i found 1 solution of that and i manually add the report viewer on form using code.
but now i don't know how can i show my rdlc report on this report viewer.
please any one tell me how can i show my Report1.rdlc in ReportViewer1.
if you have any sample code then please send me thanks.

What I have tried:

i use this code on form load event

ReportParameterCollection rpera = new ReportParameterCollection();
           rpera.Add(new ReportParameter("Pname", "Its first Report"));
           this.reportViewer1.LocalReport.SetParameters(rpera);
           this.reportViewer1.RefreshReport();
Posted
Updated 27-Feb-19 6:05am
Comments
[no name] 22-Feb-19 10:14am    
Where's the part where you "bind to a data source"?
Fahid Zahoor 22-Feb-19 10:25am    
at that moment there is no data source that i bind. i just display "Its first Report" on my rdlc report.
Fahid Zahoor 22-Feb-19 10:36am    
please you tell me how can id display my Report1.rdl in ReportViewer1

1 solution

Hi There,

I may be mistaken, but .rdl files belong to SQL Reporting Services (SSRS), and ReportViewer is the winforms/webforms control that handles .rdlc files. Your code sample seems to belong to a webform.

Having mentioned that, most of the required code for both winforms/webforms is basically the same, but there are some minor differences that must not be ignored.

Webform example(rptVwr is the name I gave to the ReportViewer control):
DataSet ds = Your method to get the required data;

            rptVwr.ProcessingMode = ProcessingMode.Local;
            rptVwr.LocalReport.EnableExternalImages = true;
            rptVwr.LocalReport.ReportPath = "Reports/DTE.rdlc";
            rptVwr.LocalReport.DataSources.Clear();
            rptVwr.LocalReport.DataSources.Add(new ReportDataSource("Dcto", ds.Tables[0]));
            rptVwr.LocalReport.DataSources.Add(new ReportDataSource("Events", ds.Tables[1]));
            rptVwr.LocalReport.DataSources.Add(new ReportDataSource("AuxData", ds.Tables[2]));
            rptVwr.LocalReport.Refresh();


Winforms Example (RepVwer is the name I gave to the ReportViewer control):
... DataSet ds = here goes your method to get the required data;

RepVwer.ProcessingMode = ProcessingMode.Local;
                RepVwer.LocalReport.ReportEmbeddedResource = "DTEViewer.rdlc.DTE.rdlc";

                RepVwer.LocalReport.DataSources.Clear();
                RepVwer.LocalReport.DataSources.Add(new ReportDataSource("IdDoc", ds.Tables[0]));
                RepVwer.LocalReport.DataSources.Add(new ReportDataSource("Emi", ds.Tables[1]));
                RepVwer.LocalReport.DataSources.Add(new ReportDataSource("Recep", ds.Tables[2]));
                RepVwer.LocalReport.DataSources.Add(new ReportDataSource("Details", ds.Tables[3]));
                RepVwer.LocalReport.DataSources.Add(new ReportDataSource("Totals", ds.Tables[4]));
                this.RepVwer.RefreshReport();

If your need to pass parameters to a report, create the array, assign all needed values, and add it to the report:
ReportParameter[] repParams = new ReportParameter[3];
repParams[0] = new ReportParameter("MyParam1", "false");
repParams[1] = new ReportParameter("MyParam2", nroOper);
repParams[2] = new ReportParameter("MyParam3", "blah, blah, blah!");
LocReport.LocalReport.SetParameters(repParams);

That's how I configure ReportViewer controls, assign the report to use, bind data, and finally display them.

Hope this helps; cheers!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900