How the subreport take parameter value from the main report?
I have a main report and a sub report. the main report is to display the billing report and the subreport is to display detail tarif of the billing. the both report work well stand alone. the subreport should take 3 parameter from the main report values. they are idtarif,date_periode and water_usage. I dont know how the subreport take paramaters value from the main report. in code DetailTarifSubreportProcessingEventHandler below i have to hardcode the parameter to make the subreport work. I want the subreport take the parameters value dynamically from the main report. Here is the code from showreport.cs public showreport(string sqlwhere) { sql = "call sp_water_bill('" + con + "','" + sqlwhere + "')"; runReportSub("reports/report_water_bill_print.rdlc","Data",loadDataChart(sql),"Report"); } private void runReportSub(string rdlc,string dataset,DataTable data,string title) { this.Text = title; this.ClientSize = new System.Drawing.Size(750, 750); rpt.ProcessingMode = ProcessingMode.Local; rpt.LocalReport.ReportPath = rdlc; rpt.LocalReport.DataSources.Add(new ReportDataSource(dataset,data)); rpt.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(DetailTarifSubreportProcessingEventHandler); rpt.Dock = DockStyle.Fill; this.Controls.Add(rpt); rpt.RefreshReport(); } void DetailTarifSubreportProcessingEventHandler(object sender, SubreportProcessingEventArgs e) { DataTable detailTarifData = null; //the subreport should take 3 parameter from the main report values. they are idtarif,date_periode and water_usage string sqlsub = "call sp_detail_tarif('3','2008-08-01','41')";//-->hard code to test the subreport and it work if (detailTarifData == null) detailTarifData = loadDataChart(sqlsub); e.DataSources.Add(new ReportDataSource("Data",detailTarifData)); }
August 7th, 2011 7:18pm

Hi Advcha, You can use the following syntax in the DetailTarifSubreportProcessingEventHandler function String idtarif= args.Parameters[0].Values[0]; or String idtarif= args.Parameters[" idtarif "].Values[0]; Try to set the parameter for the subreport in your main report. Take the following step. 1. Right click on the subreport on main report, choose Properties item. 2. Choose the parameter tab on the popup dialog. 3. Set the parameter of your subreport to corresponding field. Regards, Tarek Ghazali
Free Windows Admin Tool Kit Click here and download it now
August 8th, 2011 4:12am

Hi advcha, As Tarek Ghazali mentioned, we have an easy way to pass parameter values from the main report to subreport, and Tarek Ghazali has given the main steps above. One thing I’d like to implement here is, there might be various approaches to pass parameter values to subreport, such as though a parameter in main report, though certain selected values in current scope, and though a specific value in a multi-value parameter. For more details, there is a good reply from Robert Bruckner in this thread: http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/ae5ac615-1076-428d-9fcf-6c27e5fee1f0/ There is also an article in MSDN library, which gives detailed steps of the general method to Specify parameters to pass to a subreport: http://msdn.microsoft.com/en-us/library/ms160348(v=sql.100).aspx Hope it really helps to simplify your work and make the report exactly as you required. Thanks, Lola Please remember to mark the replies as answers if they help.
August 9th, 2011 6:04am

Hi Ad Try below thing it will help ReportDocument cryRpt = new ReportDocument(); cryRpt.Load("rptMainReport.rpt"); cryRpt.SetParameterValue("myRoleId", 2, "subreport name"); And fill in the proper value for the subreport name.SUHAS http://suhaskudekar.blogspot.com/ Please click "Mark as Answer" if this resolves your problem or "Vote as Helpful" if you find it helpful.
Free Windows Admin Tool Kit Click here and download it now
August 9th, 2011 6:56am

Nobody seems to understand that the sub-report data needs to be shown /filtered based on the main report column values. Sorry for complaining but after spending quite a time, I figured this out. We need to define report parameters as mentioned above in the subreport, we need to pass the parameter values to the datasource used by sub-report to get the required data. Given below is the code, I have used to populate teh subreport Objectdatasource. Public Sub SubreportProcessingEventHandler(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs) 'e.Parameters.Item(0) is the report parameter defined in Sub-report ObjectDataSource2.SelectParameters("Param1") = New Parameter("Param1", DbType.Int32, e.Parameters.Item(0).Values(0)) ObjectDataSource2.SelectParameters("Param2") = New Parameter("Param2", DbType.String, e.Parameters.Item(1).Values(0)) e.DataSources.Add(New ReportDataSource("SubReportDataSourceName", ObjectDataSource2)) End Sub Hope this helps!!! Baskar
January 15th, 2012 12:01am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics