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

Dynamic sub-report

1 Answer 156 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Lucania
Top achievements
Rank 1
Lucania asked on 01 Mar 2012, 04:01 AM
I have a report in which I want to use a different sub-report for each detail item depending on a value in the item data. For example:

If type=1, Use sub-report Sub1
If type=2, Use sub-report Sub2
etc.

Is this possible? If so, how? I've tried putting a SubReport in the detail, and in the detail_ItemDataBound set the SubReport.ReportSource, but it doesn't seem to work. Any ideas gratefully received.

Thanks

Ross Crawford

1 Answer, 1 is accepted

Sort by
0
Lucania
Top achievements
Rank 1
answered on 02 Mar 2012, 07:26 AM
OK I think I've got it working now, a couple of things I was doing wrong:
  1. Trapping detail_ItemDataBound - this is too late to effect the change! Putting the code in detail_ItemDataBinding worked well
  2. It seems the objects in the detail section are global - there's only one instance that is re-used for every record. So I had to specifically set the SubReport's ReportSource to null on the records that don't need a sub-report, otherwise they used the one from the previous record!
  3. A sub-report set dynamically like this does not use the connection specified in the report, I had to expose the connection string in the report class, and set it in the main report.

After fixing these, it seems to work well.

Ross Crawford
Tags
General Discussions
Asked by
Lucania
Top achievements
Rank 1
Answers by
Lucania
Top achievements
Rank 1
Share this question
or