Link to home
Start Free TrialLog in
Avatar of Scarlett72
Scarlett72

asked on

Change datasource for report viewer control programatically

Hi, how can I change the <rsweb:ReportDataSource DataSourceId= property of a report viewer control from
ObjectDataSource1 to ObjectDataSource2?
Avatar of jitendra patil
jitendra patil
Flag of India image

in the code behind you can try the following code as below

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

"datasourcename" 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.

hope this helps.
Avatar of Scarlett72
Scarlett72

ASKER

Hi Jitendra, thank you for replying.
So in my .rdlc file,
my Data Source is called:  "RF"
and
my dataset is called dsSalesDelta
So would would the arguments in new ReportDataSource look like this?

reportViewer.LocalReport.DataSources.Add(new ReportDataSource("RF", dsSalesDelta));

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jitendra patil
jitendra patil
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial