The Master-Detail using Subreports documentation makes sense when your data is coming from a database, but not when you are using an ObjectDataSource and you want your subreport to be bound to a collection property on that object.
I got this working but was looking for some feedback as to if I'm doing this the hard way and also as a reference as the docs seem lacking in this area.
I got this working but was looking for some feedback as to if I'm doing this the hard way and also as a reference as the docs seem lacking in this area.
readonly
System.Xml.XmlReaderSettings _settings =
new
System.Xml.XmlReaderSettings { IgnoreWhitespace =
true
};
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
Telerik.Reporting.Report report;
using
(System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(@
"Report.trdx"
, _settings))
{
var xmlSerializer =
new
ReportXmlSerializer();
report = (Telerik.Reporting.Report)xmlSerializer.Deserialize(xmlReader);
}
report.DataSource = GetDataSource();
//List<ParentObject>
var reportProcessor =
new
Telerik.Reporting.Processing.ReportProcessor();
var instanceReportSource =
new
InstanceReportSource { ReportDocument = report };
report.Items[
"detail"
].ItemDataBinding += ReportOnItemDataBinding;
...
}
}
private
void
ReportOnItemDataBinding(
object
sender, EventArgs eventArgs)
{
var detailSection = sender
as
Telerik.Reporting.Processing.DetailSection;
using
(System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(@
"SubReport.trdx"
, _settings))
{
var xmlSerializer =
new
ReportXmlSerializer();
var subReport = (Telerik.Reporting.Report)xmlSerializer.Deserialize(xmlReader);
subReport.DataSource = ((ParentObject)detailSection.DataObject.RawData).Children;
var sr = (SubReport)detailSection.ItemDefinition.Items[
"subReport1"
];
sr.ReportSource =
new
InstanceReportSource {ReportDocument = subReport};
}
}