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

SubReport Items Empty in Q2 2012 Release

4 Answers 166 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Aaron
Top achievements
Rank 1
Aaron asked on 15 Jul 2012, 09:08 PM
Hi,

I have been using Telerik Reporting for the past couple of years. I upgraded my applications to use Q2 2012 and as a result some of the functionality that I had in place no longer works and I can't find a working alternative.

Structure:

- Master report with 3 subreports.
- Each subreport has a chart
- I set the chart series in the Page_Load event of the ASPX page that renders the report

Problem:

This doesn't work anymore - the Items collection for the SubReport is always empty. Before upgrading to Q2 2012 this worked fine.
// Get the chart from the subreport
    var individualContributionsReportChart = (Telerik.Reporting.Chart)individualContributionsReport.ReportSource.Report.Items["labelsGroupHeader"].Items["chart1"];


Code Example (I stripped out application logic that has nothing to do with the reports):
protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        TotalContributionsOverviewReport report = new TotalContributionsOverviewReport();
 
        var individualContributionsReport = ((Telerik.Reporting.SubReport)(report.Items["reportFooter"].Items["IndividualContributionsSubReport"]));
        GetIndividualContributionsChart(individualContributionsReport, startDate, endDate, categoryNameFilter, categoryIdFilter);
 
        ReportViewer1.Report = report;
    }
}
 
private void GetIndividualContributionsChart(Telerik.Reporting.SubReport individualContributionsReport,
            DateTime startDate, DateTime endDate, string categoryNameFilter, string categoryIdFilter)
{
    // Get the chart from the subreport
    var individualContributionsReportChart = (Telerik.Reporting.Chart)individualContributionsReport.ReportSource.Report.Items["labelsGroupHeader"].Items["chart1"];
 
    // Get the chart data
    var records = PersistenceFactory.GetRecords();
 
    var categoryGroups = records.GroupBy(r => r.CategoryName);
    foreach (var g in categoryGroups)
    {
        // Create a ChartSeries and assign its name and chart type
        ChartSeries chartSeries = new ChartSeries();
        chartSeries.Name = g.Key;
        chartSeries.Type = ChartSeriesType.Line;
        // add new items to the series,
        // passing a value and a label string
        foreach (var c in g)
        {
            ChartSeriesItem item = new ChartSeriesItem()
            {
                XValue = c.ContributionDate.ToOADate(),
                YValue = Convert.ToDouble(c.Amount)
            };
            chartSeries.Items.Insert(chartSeries.Items.Count, item);
        }
 
        // add the series to the Chart Series collection
        individualContributionsReportChart.Series.Add(chartSeries);
 
        // format the chart axis
        FormatChartAxis(individualContributionsReportChart, startDate, endDate, step);
    }
}

4 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 16 Jul 2012, 01:09 PM
this code is deprecated
ReportViewer1.Report = report;

you have to declare a ReportSource and use that instead
http://www.telerik.com/help/reporting/t_telerik_reporting_instancereportsource.html
0
Aaron
Top achievements
Rank 1
answered on 16 Jul 2012, 02:31 PM
Thanks for the reply, unfortunately that didn't work however.

I changed the instantiation of the report to
Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
var report = new Foundation.Reporting.TotalContributionsOverviewReport();
ReportViewer1.ReportSource = instanceReportSource;

and I also changed the call on the SubReport because the previous statement is throwing an exception
var individualContributionsReportChart = (Telerik.Reporting.Chart)individualContributionsReport.Items["labelsGroupHeader"].Items["chart1"];

Unfortunately the subreport items collection is still empty (
individualContributionsReport.Items
).
0
Accepted
Elian
Telerik team
answered on 18 Jul 2012, 08:31 AM
Hello Aaron,

To be able to modify items in a report that serves as a sub-report, you will have to modify a bit your application. Since the introduction of the new Report Sources, the ReportSource property of the SubReport item is now of type ReportSource (not Report like before). 

Here is a sample code that reflects the changes:
//instantiate new report - the one that will serve as a subreport
var subReport = new DetailReport();
//find the item you wish to edit
var chart = subReport.Items.Find(typeof(Telerik.Reporting.Chart), true)[0] as Telerik.Reporting.Chart;
//edit the item ...
chart.DataSource = ...
 
//instantiate the master report
var masterReport = new MasterReport();
//find the subreport item inside the master report
var subRepItem = report.Items.Find(typeof(Telerik.Reporting.SubReport), true)[0] as Telerik.Reporting.SubReport;
//set it's report source to a new InstanceReportSource with the report document that you have already instantiated above
subRepItem.ReportSource = new InstanceReportSource { ReportDocument = subReport };
//display the master report in the viewer
this.ReportViewer1.ReportSource = new InstanceReportSource { ReportDocument = masterReport };

If you are using InstanceReportSource already in the master report (and that is the case if this is an old report), then you can take the SubReportItem.ReportSource and cast it directly (instead of instantiating new DetailReport) if that works better.
 

// Get the subreport normally here
// And after that you have to get the ReportSource knowing it is a InstanceRportSource
var repSource = (InstanceReportSource)mySubReport.ReportSource;
  
// Because you know the ReportDocument is a Report (not a ReportBook)
var report = (Telerik.Reporting.Report)repSource.ReportDocument;
var myChart = (Telerik.Reporting.Chart) report.Items["labelsGroupHeader"].Items["chart1"];
// do whatever you need/want with that item

Hope this helps.

Kind regards,
Elian
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

0
Aaron
Top achievements
Rank 1
answered on 19 Jul 2012, 09:52 PM
Thanks, that worked!!!
Tags
General Discussions
Asked by
Aaron
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
Aaron
Top achievements
Rank 1
Elian
Telerik team
Share this question
or