views:

160

answers:

1

How do I programmaticly set data source for Asp.net report control?

I have a VS 2008 report control and want to switch between a couple different reports.

I can switch repots by setting the report source and refreshing the control but I can't see where to set the data source.

Each report has it's own data source and if I set them to start when the control is built it is fine but I need to switch between them.

+1  A: 

I assume the question is about ReportViewer control.

reportViewer.LocalReport.DataSources.Clear();
reportViewer.LocalReport.DataSources.Add(new ReportDataSource("dsname", source));

"dsname" is the name of the data source, you can find it .rdlc file. source is the variable with data you want to show in the report.

Alexander Shirshov
When I I do this I get"# An error has occurred during report processing. * A data source instance has not been supplied for the data source ...."
Maestro1024
And the supplied data source listed in the data source for the default report that I originally setup. It is like the new data source is not really being set.
Maestro1024
I am still looking at this. Wondering if I have the wrong "source name". How do I see the source used in the report?
Maestro1024
I found the source name in the main aspx page not in the report.
Maestro1024