Using subreport inside an SSRS table/tablix cell
In my application I have a report with one subreport开发者_运维问答 contained inside a table cell. Within the SubreportProcessing event handler I supply a different set of data foreach instance of the subreport. In VS 2008 this worked okay. However, when I switched over to VS2010 and upgraded the report file format, the behavior changed. All subreport instances in the master table now contain the data that I supplied for the first table row. My code looks like this
void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
// _index is a global variable that is reset to zero in the DataBind procedure.
Trip currentTrip = _trips[_index];
e.DataSources.Add(new ReportDataSource("DataSourceName", currentTrip.Items));
_index++;
}
Is this the intended behavior? How can I now supply different datasets for multiple instances of the same subreport inside a table?
Thanks in advance.
Vladislav
After some poking around and tinkering with my code, I found a workaround. The solution is to create a dummy parameter in the subreport, which you then need to bind to a field in the tablix dataset. Any field will do as long as both the subreport parameter and the tablix dataset field are type-compatible. You don't have to do anything with the parameter in the subreport, but now SSRS displays multiple instances of the same subreport, a separate one for each row in the tablix.
Hope this will be helpful for someone else, too.
Vladislav
精彩评论