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

Pass DataSet to SubReport

2 Answers 189 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Adam S
Top achievements
Rank 1
Adam S asked on 29 Oct 2009, 07:09 PM
I'm trying to pass a DataSet to a SubReport. I don't want the DataSet to be the SubReport's DataSource. The SubReport has a chart and table in it which will display the contents of the passed DataSet.

The only way I see to pass values to a SubReport is via ReportParameters. That, however, does not allow passing objects. Doing SubReport.ReportSource on DetailSection.ItemDataBound leaves the first detail section without a DataSet.

 
private void detail_ItemDataBound(object sender, EventArgs e) 
    Telerik.Reporting.Processing.DetailSection detailSection = (Telerik.Reporting.Processing.DetailSection)sender; 
 
    DataRow row = (DataRow)detailSection.DataObject.RawData; 
 
    TUsageSubReport subReport = (TUsageSubReport)this.UsageSubReport.ReportSource; 
 
    DataSet ds = null
 
    DB.Reports_GetAccountUsages(Convert.ToInt32(row["UserId"]), new DateTime(2009, 10, 1), new DateTime(2009, 10, 31), m_ConnectionString, out ds); 
 
    subReport.Usages = ds; 
 

Is it possible to get to the actual report object (SubReport.ReportSource) per detail section?

2 Answers, 1 is accepted

Sort by
0
Adam S
Top achievements
Rank 1
answered on 30 Oct 2009, 01:01 PM
Nevermind. I switching to detail_ItemDataBinding solved this issue.
0
Steve
Telerik team
answered on 02 Nov 2009, 04:51 PM
Hello Adam S,

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 "missing" the first record. For each record of the main report the following sequence of events occurs:

1. The ItemDataBinding event occurs just before thereport is processed;
2. The NeedDataSource event occurs if the report does not have a data source;
3. The report items are processed and their values are added to the generated result;
4. The ItemDataBound event occurs right after the 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.
Also looking at your code there is no obvious reason why you would want to pass the dataset in the main report code, instead of the NeedDataSource event of the report used as subreport instead.

All the best,
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.
Tags
General Discussions
Asked by
Adam S
Top achievements
Rank 1
Answers by
Adam S
Top achievements
Rank 1
Steve
Telerik team
Share this question
or