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

Programmatically setting XML source type sub report datasource

2 Answers 176 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
John North
Top achievements
Rank 1
John North asked on 22 Oct 2012, 04:56 PM

Followed the advice form this link below but still no luck
http://www.telerik.com/community/forums/reporting/telerik-reporting/how-do-you-programmatically-bind-subreports-in-q2-2012.aspx

Telerik.Reporting.SubReport mySubReport = (Telerik.Reporting.SubReport)oReport.Items.Find("MySubReport", true)[0];

//*** This is working
// this code block loads the data in sub report in this case if i set the subreport as an object Instance

var repSource = (InstanceReportSource)mySubReport.ReportSource;
var subreport = (Telerik.Reporting.Report)repSource.ReportDocument;
var odsItems = (Telerik.Reporting.ObjectDataSource)subreport.DataSource;
subreport.DataSource = objectDataSource;

//*** End

//*** This is not working
// this code block doesn't load the data in sub report in this case if i set the subreport as an XML Source (serialized report using ReportXmlSerializer)
var repSource = (XmlReportSource)kpiActionsSubReport.ReportSource;
Report subreport = TelerikReportHelper.DeSerilizeTelerikReportXML(XElement.Parse(repSource.Xml)); //(deserialized report using ReportXmlSerializer)
subreport.DataSource = objectDataSource;
//*** End

2 Answers, 1 is accepted

Sort by
0
Elian
Telerik team
answered on 25 Oct 2012, 03:05 PM
Hello John,

You are assigning the objectDataSource to a report object which you have deserialized but this report object is in no way connected to the main report. In order for this to work, you should set the deserialized report as a ReportSource of the SubReport item. For example:

subreport.DataSource = objectDataSource;
kpiActionsSubReport.ReportSource = new InstanceReportSource { ReportDocument = subreport };


Hope this helps.

Greetings,
Elian
the Telerik team

HAPPY WITH TELERIK REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

0
John North
Top achievements
Rank 1
answered on 27 Oct 2012, 02:35 AM
Thanks Elian for your reply. It worked like a charm.
Tags
General Discussions
Asked by
John North
Top achievements
Rank 1
Answers by
Elian
Telerik team
John North
Top achievements
Rank 1
Share this question
or