Using subreports in a Crystal Reports XI report in a ASP.NET webapplication, with the datasource dynamically set.
While using a Crystal Reports report which contains one or more subreports, the following syntax (the most logical) does not give the expected behaviour:

What happens is that the main report is shown with data as expected, but the sub report(s) are always empty.
When I googled, I found some people had the same experience. Nobody came up with an answer that solved this problem.
A developer on my team asked Business Objects by mail and at first got some links that were not even related to the problem. After a few weeks he recieved the following code snippet, which after we changed it to fit our purpose did the trick.
Code snippet

The solution is to loop through all sections in the main report and than loop through all objects per section.
In the 'objects' loop we check to find if the ObjectKind is of ObjectKind.SubreportObject.
If this is the case we have to check if the name of this subreport matches the subreport we need.
If this is the case the datasource is set with the following syntax:
crSubReportDoc.Database.Tables[0].SetDataSource(ds);

I suspect that this is the trick.
The looping to find the right subreport object might not have any use.

Henry Cordes
My thoughts exactly...

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading