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

Is it possible hand a report a list to bind to?

3 Answers 87 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Timothy
Top achievements
Rank 1
Timothy asked on 10 Jul 2012, 05:06 AM
Ideally, I would like to do accomplish the following:

IEnumerable<MyPoco> pocos = _reportingTasks.GetMyPocos();

 var report = new MyPocoReport {DataSource = pocos};

ReportViewer1.ReportSource = new InstanceReportSource {ReportDocument = report};


Basically, because of how are dependencies are set up, I would like to hand my report a pre-populated list rather than setting the DataSource and DataMember properties on the objectDataSource and letting the report execute my query.  All the examples I have found either perform data access in the DataSource object or pre-populate a collection in the constructor (like the List Bound report demo).  Any thoughts?

3 Answers, 1 is accepted

Sort by
0
IvanY
Telerik team
answered on 12 Jul 2012, 11:13 AM
Hello Timothy,

If I have understood you correctly what you want to do is this:
var myList= SomeMethodThatReturnsList();
 
var ds = new ObjectDataSource
  {
    DataSource = myList
  };
 
var report1 = new Report1();
report1.DataSource = ds;
 
this.viewer1.ReportSource = new InstanceReportSource { ReportDocument = report1 };

Please note that the DataSource of the report cannot be a simple list or IEnumerable for example - it has to be one of the following types: Entity, Object, SQL, Cube or Open Access data source.

All the best,
IvanY
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

0
Timothy
Top achievements
Rank 1
answered on 12 Jul 2012, 04:17 PM
Just to be clear, are you saying your code example  works?
0
IvanY
Telerik team
answered on 13 Jul 2012, 04:11 PM
Hi Timothy,

Yes the example is runnable, you will have only to assign DataMember as well if the class you are using is not a data class and you are relying on a method in it that returns data. But having in mind your code from the previous ticket, the proposed snippet will be enough.

Greetings,
IvanY
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

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