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

Two of same Report in one ReportBook, different parameters

3 Answers 414 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tristan
Top achievements
Rank 1
Tristan asked on 15 Dec 2015, 02:08 PM

I'm trying to create a compilation of several instances of the same report using a ReportBook. 

 The issue I'm having is that although I'm instantiating separate instances of the report and setting the date parameter for each, all the reports are returning data for the same date, rather than for their individual parameter dates.

 

My code:

ReportBook reportBook = new ReportBook();
 
reportBook.Reports.Add(new TestReport());
reportBook.Reports.Add(new TestReport());
 
reportBook.Reports[0].ReportParameters["date"].Value = new DateTime(2015, 10, 1);
reportBook.Reports[1].ReportParameters["date"].Value = new DateTime(2015, 10, 2);
 
 
var instanceReportSource = new InstanceReportSource();
instanceReportSource.ReportDocument = reportBook;
reportViewer.ReportSource = instanceReportSource;
 
reportViewer.RefreshReport();

I'm working in C#; the report is included in the Visual Studio project as an object (not a seperate .trdx), with an ObjectDataSource using an externally referenced Entity Framework repository; the DataMember is a method of the EF repository that is essentially 'GetThingsForDate(DateTime date)'.

 

Any insight much appreciated!

3 Answers, 1 is accepted

Sort by
0
Tristan
Top achievements
Rank 1
answered on 15 Dec 2015, 04:39 PM
I'm not sure if it's the "correct" way to solve the issue above, but I managed to get this working as I wanted by manually defining a new ObjectDataSource for each instance of the report:
var report1 = DeserializeReport(@"Reports\Test Report.trdx");
var objectDataSource1 = new ObjectDataSource(typeof(EntityFrameworkRepository), "GetThingsForDate");
objectDataSource1.Parameters.Add("date", typeof(DateTime), new DateTime(2015, 10, 1));
report1.DataSource = objectDataSource1;
 
var report2 = DeserializeReport(@"Reports\Test Report.trdx");
var objectDataSource2 = new ObjectDataSource(typeof(EntityFrameworkRepository), "GetThingsForDate");
objectDataSource2.Parameters.Add("date", typeof(DateTime), new DateTime(2015, 10, 2));
report2.DataSource = objectDataSource2;
 
ReportBook reportBook = new ReportBook();
reportBook.Reports.Add(report1);
reportBook.Reports.Add(report2);
 
var instanceReportSource = new InstanceReportSource();
instanceReportSource.ReportDocument = reportBook;
reportViewer1.ReportSource = instanceReportSource;
 
reportViewer1.RefreshReport();

 

That's also using the DeserializeReport method posted by one of the admins elsewhere on these forums, to allow for the report to be included as a .trdx rather than a class object, as recommended in the best practices section of the documentation:

public Report DeserializeReport(string path)
{
    System.Xml.XmlReaderSettings settings = new System.Xml.XmlReaderSettings();
    settings.IgnoreWhitespace = true;
 
    using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(path, settings))
    {
        Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer = new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();
        Telerik.Reporting.Report report = (Telerik.Reporting.Report)xmlSerializer.Deserialize(xmlReader);
 
        return report;
    }
}

0
Accepted
Nasko
Telerik team
answered on 17 Dec 2015, 03:18 PM
Hello Tristan,

Telerik Reporting provides a mechanism known as parameter merging. If the Name and Type of two (or more) parameters from different reports are the same, then they are considered equivalent and are displayed as a single parameter in the parameters area. When one or more parameters are merged the UI settings (and value) of the first one are used for displaying it in the parameters area.
You can control parameter merging via the Mergeable boolean property of the report parameter. The default value of the Mergeable property is true. Set the Mergeable property to false if you want to prevent a parameter from being merged with its equivalent ones.
Additional information is available in the Report Book  help article.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Tristan
Top achievements
Rank 1
answered on 21 Dec 2015, 10:47 AM

A big thank you to you Nasko!

This is what I needed to generate a report book with multiples of the same report with different parameters.

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