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

Set subreport datasource to datatable runtime

6 Answers 285 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Brant
Top achievements
Rank 1
Brant asked on 13 Nov 2009, 10:55 PM
I am trying to set a subreport's datasource at runtime from the master.  This works great when I can pass the foreign key to the master report via parameters so that I can generate the right data at runtime for the subreport.  Now I have a master report that is generated from a date range.  I am getting the value of the foreign key needed for the subreport from a textfield on the master report.  This works great except for the first record in the master report.  It seems the datasource works on the supreport for any record after that.  I have tried everything, and they all ohave the same result.  I am using Telerik.Q2 2008.  I love this product, but I can't get past this one issue.  See screen shot of page 1 of report and then of the code I am using.  Thanks!

6 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 16 Nov 2009, 03:29 PM
Hi Brant,

As described in this help topic from the online help, the ItemDataBound event occurs after the current report/sub-report is data bound which is too late to specify the data source. This explains why the records of your sub-report are shifted one record behind the main report. For each record of the main report the following sequence of events occurs for the sub-report:

1. The ItemDataBinding event occurs just before the sub-report is processed;
2. The NeedDataSource event occurs if the sub-report does not have a data source;
3. The sub-report is processed and its records are added to the generated result;
4. The ItemDataBound event occurs right after the sub-report is processed.

It is evident that if you specify a data source in the ItemDataBound event that data source should not be used until the next iteration, hence the records of the sub-report should lag one record behind the main report. To avoid this you should always specify the data source in the NeedDataSource event instead which is meant for this sole purpose.

Best wishes,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Brant
Top achievements
Rank 1
answered on 16 Nov 2009, 03:39 PM
Steve,
I understand the events, but I don't understand where to get the value of a date range from the master report to create the datasource for the sub report.  In the ItemDatabinding event of the master report, there is no value in those fields, in the sub report needdatasource event, there is still no value in those fields.  Should this be done strictly through parameters?
0
Ivan
Telerik team
answered on 18 Nov 2009, 01:35 PM
Hello Brant,

You need to handle the NeedDataSource event of the SubReport item within the main report. If you use the build-in parameter UI you can access the parameter values from the ReportParameters collection of the main report. Please visit this help topic from the online documentation for more information regarding this. The last section provides an example code snippet that does exactly what you want.
 

Kind regards,
Ivan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Brant
Top achievements
Rank 1
answered on 18 Nov 2009, 07:47 PM
Actually I figured this out.  I can create the datasource for the subreport on the master databinding event and utilize the sub report paramter/filter from the master to get it to work correctly.   Thanks for your help on this.
0
smith spd
Top achievements
Rank 1
answered on 29 Sep 2010, 07:50 PM

Hello Brant,

Can you post your code here..to achieve dynamic binding of the subreports
corresponding to Main report.I have the similar issue and its driving me crazy...

Thank you,
Smith

0
Brant
Top achievements
Rank 1
answered on 01 Oct 2010, 10:13 PM
Smith,
Sorry for my delay as I have been out of the office.  I will post my code over the weekend.  It essentially very easy, if you need a value from a textbox on the parent report, use the itemdatabound event of that particular text box.  Then you dim the text box as a report.processing item (all done form my memory but I found this in the Telerik help).  At that point you can get your data with the right value from that text box.  I simply use an OLEDB command to fill a datatable and set the subreport datasource to the datatable and it is good from there.

Brant
Tags
General Discussions
Asked by
Brant
Top achievements
Rank 1
Answers by
Steve
Telerik team
Brant
Top achievements
Rank 1
Ivan
Telerik team
smith spd
Top achievements
Rank 1
Share this question
or