This is a migrated thread and some comments may be shown as answers.

setting datasource for multiple subreports programmatically

1 Answer 289 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
john81
Top achievements
Rank 1
john81 asked on 26 Jan 2010, 02:50 PM
I have a master report that has no datasource.  It simply contains 2 subreports.  I want to set the datasource for my subreports programatically from my web application.  I need to do this because the datasources are web services which I'm converting to datasets. The code I have below is running but no data is shown on the report.  When I debug and step through the code the subreports have the correct datasets as their datasouces.  Any ideas on what I'm doing wrong?  Do I need to do something to the main report before running it?

        // get a reference to the master report
        Telerik.Reporting.Report rptMain = new my_report();

        // get a reference to the subreports
        Telerik.Reporting.SubReport rptSub1 = (Telerik.Reporting.SubReport)rptMain.Items.Find("subReport1", true)[0];
        Telerik.Reporting.SubReport rptSub2= (Telerik.Reporting.SubReport)rptMain.Items.Find("subReport2", true)[0];

        // get the datasets for the subreports by converting xml from web service calls into datasets
        DataSet ds1 = GetDataSetForSubReport1();
        DataSet ds2 = GetDataSetForSubReport2();

        // set the subreport datasources
        rptSub1.ReportSource.DataSource = ds1;
        rptSub2.ReportSource.DataSource = ds2;
 
        // open the report as a pdf file
        ReportProcessor reportProcessor = new ReportProcessor();
        RenderingResult result = reportProcessor.RenderReport("PDF", rptMain, null);
        ...




 

1 Answer, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 29 Jan 2010, 10:07 AM
Hi john81,

The code you've pasted is correct. I assume that it is an excerpt, but still in order to show it in PDF file, you should use a memory or file stream and save it to a file e.g.:

ReportProcessor reportProcessor = new ReportProcessor();
RenderingResult result = reportProcessor.RenderReport("PDF", rptMain, null);
 
FileStream fs = new FileStream("c:\\report1.pdf", FileMode.Create);
fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
fs.Flush();
fs.Close();

Another thing that comes to mind is whether you have set valid expressions to the report items in the report you bind e.g. "=Fields.MyField" and MyField exists in the datasets you're feeding it with.

Kind regards,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
General Discussions
Asked by
john81
Top achievements
Rank 1
Answers by
Steve
Telerik team
Share this question
or