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

HTML5 Report Viewer - Using Models - Part two

2 Answers 13 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
steve
Top achievements
Rank 1
steve asked on 30 Nov 2016, 08:48 PM

Trying to follow this original thread:http://www.telerik.com/forums/asp-net-mvc4-using-pass-model-to-objectdatasource#n3Sejx7cSEKjJ3clQNeH7w which is closed.

 

I modified the mvc project to display the ListBoundReport directly, using a custom resolver.

 

public class CustomReportResolver : IReportResolver
    {
        ReportSource IReportResolver.Resolve(string report)
        {
          
            var nreport = new ListBoundReport();

            var ds = new Cars().GetRange(1, 2);

            nreport.DataSource = ds;
            var irs = new InstanceReportSource { ReportDocument = nreport };
 
            return irs;
        
        }
    }

 

This displays the same 7 original cars

            nreport.DataSource = null; did not clear the items

If I remove the datasource from the report (objectDataSource1.DataSource) It will display two records, but both will be blank (not tied to the values).

Please explain both behaviors:

1. Why setting the Datasource has no effect

2. Why after removing Datasource from report only works half way (not bound to fields)

And what we need to do to get this to work correctly

Thanks, 

Steve

 

2 Answers, 1 is accepted

Sort by
0
steve
Top achievements
Rank 1
answered on 30 Nov 2016, 09:40 PM

update to this.

 

When doing as in this sample code you actually get seven items on two pages instead of one.

0
Katia
Telerik team
answered on 05 Dec 2016, 08:23 AM
Hi Steve,

When a report has inner data items their DataSource properties need also to be set. Data items will not reuse the report's data source by default.

In ListBoundReport report, the data fields are placed in a List item. If you want to change its DataSource property in a custom report resolver it can be achieved as following:
ReportSource IReportResolver.Resolve(string report)
        {
 
            var nreport = new ListBoundReport();
 
            var ds = new Cars().GetRange(1, 2);
 
            //nreport.DataSource = ds;
            List listItem = (List)nreport.Items.Find("list1", true)[0];
            listItem.DataSource = ds;
 
            var irs = new InstanceReportSource { ReportDocument = nreport };
 
            return irs;
 
        }

You can also check Changing the connection string dynamically according to runtime data KB article that provides an example of how to iterate over DataSource properties of inner data items in order to change them at runtime.

When you set a DataSource property of both report and data item, the data will be repeated (Data Binding Problems) as the list item will be repeated for each data row from the report's data source.
To avoid this, set only the inner data item's DataSource property or reuse the parent's (report's) data source as described in Binding a Data item to Data help article.


I hope this information will help.

Regards,
Katia
Telerik by Progress
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
Tags
General Discussions
Asked by
steve
Top achievements
Rank 1
Answers by
steve
Top achievements
Rank 1
Katia
Telerik team
Share this question
or