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

Master Detail using ObjectDataSource and Desktop Designer

2 Answers 110 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rip
Top achievements
Rank 1
Rip asked on 09 Dec 2012, 06:40 AM
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.


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};
    }
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Peter
Telerik team
answered on 10 Dec 2012, 04:19 PM
Hello Rip,

In order to use nested data collections our suggestion is to use Table or List item instead of Subreport item and set the data items' DataSource property with binding to the field representing the complex type (Children). This way the nested collection is accessible as normal field. Generally the easiest approach is to use List/Table item because you don't have to create additional report for every data level.

All the best,
Peter
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
Rip
Top achievements
Rank 1
answered on 11 Dec 2012, 04:46 AM
Thanks, that is a better way to do it. 

Just to be clear, in the table, don't set the DataSource property directly, but set the DataSource in the "Bindings".

Tags
General Discussions
Asked by
Rip
Top achievements
Rank 1
Answers by
Peter
Telerik team
Rip
Top achievements
Rank 1
Share this question
or