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

Doubt on the way to set report datasource programtically

1 Answer 15 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
abc
Top achievements
Rank 1
abc asked on 24 Apr 2017, 11:46 AM

Hi,

I am trying to set the datasource for the report using the NeedDataSource event of the report. I am able to do so as

private void BasicReport_NeedDataSource(object sender, EventArgs e)
{
Telerik.Reporting.Processing.Report mainReport = (Telerik.Reporting.Processing.Report)sender;
mainReport.DataSource = new List<string> { "test1", "test2", "test3", "test4" };
//The below commented statement leave the fields blank on the report UI
//this.DataSource = new List<string> { "test1", "test2", "test3", "test4" };
var subReportOne = new Report1();
subReportOne.DataSource = new List<string> { "item1One", "item2One", "item3One", "item4One" };
var subReportTwo = new Report2();
subReportTwo.DataSource = new List<string> { "item1Two", "item2Two", "item3Two", "item4Two" };
var subReportItemOne = this.Items.Find(this.subReportOne.GetType(), true)[0] as Telerik.Reporting.SubReport;
subReportItemOne.ReportSource = new InstanceReportSource() { ReportDocument = subReportOne };
var subReportItemTwo = this.Items.Find(this.subReportTwo.GetType(), true)[0] as Telerik.Reporting.SubReport;
subReportItemTwo.ReportSource = new InstanceReportSource() { ReportDocument = subReportTwo };
}

As you can see above, i can set the datasource for the subreports easily by getting its object but not for the report using the "this" keyword. Please can someone explain why do I need to get it explicitly from the sender instead?

Many thanks!! 

1 Answer, 1 is accepted

Sort by
0
Katia
Telerik team
answered on 24 Apr 2017, 12:32 PM
Hello abc,

Accessing report items or sections within report events by their definition (using this keyword) is not supported as of R3 2016 - Changes on items in report events are not applied.

Inside events, you can work only with processing elements - Understanding Events. To reach report's inner elements you can use ElementTreeHelper Class and its methods.

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
abc
Top achievements
Rank 1
Answers by
Katia
Telerik team
Share this question
or