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

Conditionally Change SubReport ReportSource

3 Answers 277 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 18 May 2012, 03:00 PM
Hi, I'm trying to figure out if it's possible to conditionally change the ReportSource of a Subreport in my Detail section. So, based on some value in my main datasource, I want to display a different report as the subreport.

So my thought was to wire up the ItemDataBound event of the detail section, check the value, get a reference to the subreport and set the ReportSource to the appropriate one based on the value. Like this ...

private void detail_ItemDataBound(object sender, EventArgs e)
{
    var item = sender as ReportItemBase;
    var foo = ((string)item.DataObject["Foo"]);
    var subReport = item.ChildElements.Find("SubReport1", true).FirstOrDefault() as SubReport;
 
    if (foo== "Bar") {
        var fooReport = new FooReport();
        subReport.ReportSource = fooReport;
    } else {
        // etc...
    }
}

The problem is that the SubReport that I can cast to from the item.ChildElements.Find() call is a Telerik.Reporting.Processing.SubReport. That class does not allow setting the ReportSource property. But it won't let me cast to a Telerik.Report.SubReport which is what I need to set the ReportSource. So is this even possible? If not, is there another recommended approach for this type of scenario?

Thanks,
Kevin

3 Answers, 1 is accepted

Sort by
0
Elian
Telerik team
answered on 23 May 2012, 11:42 AM
Hi Kevin,

You can find attached a project which conditionally binds subReport.Reportsource to a report instance depending on the Data. The project uses Bindings to set the subReport.ReportSource property.

Greetings,
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
Kevin
Top achievements
Rank 1
answered on 23 May 2012, 07:35 PM
Hi Elian,

Thanks! I actually ended up finding a different solution to my problem. I was able to use one subreport which had several different tables in it, all of which I set to Visible=False. Then in the ItemDataBound for that report I set one of the tables to visible based on a report parameter. It gets the job done for what I was trying to do.

It's good to know my original plan is possible though, so thanks for showing how that can be done.

Kevin
0
Steven
Top achievements
Rank 1
answered on 02 Jan 2013, 03:55 PM
The SubReport.ReportSource is now obsolute.
How can I apply Bindings to an InstanceReportSource to achieve the same result.

Is there an event that alows me access to change it directly?



Warning 1 'Telerik.Reporting.Report.implicit operator Telerik.Reporting.ReportSource(Telerik.Reporting.Report)' is obsolete: 'The implicit Telerik.Reporting.Report to Telerik.Reporting.ReportSource conversion is now obsolete. Please, use a Telerik.Reporting.InstanceReportSource object instead. For more information, please visit: http://www.telerik.com/support/kb/reporting/general/q2-2012-api-changes-reportsources.aspx#reportprocessor.' 


Nevermind

From your example I had the SubReportBuilder return an InstanceReportSource and everything worked.
Tags
General Discussions
Asked by
Kevin
Top achievements
Rank 1
Answers by
Elian
Telerik team
Kevin
Top achievements
Rank 1
Steven
Top achievements
Rank 1
Share this question
or