Wednesday, March 7, 2012

Local Report not changing back to original report

Hi
I have an aspx page which contains the report viewer control. I am using
this control in local processing mode.
Everything is working correctly except the following case
If I view a report (Report1) and then click on a hyperlink which drills down
to another report (Report2), the new report loads corectly and the
parameters are passed.
However, If I then select my generate report button on the form, it seems to
create the correct datasource and pass the right parameters, but instead of
displaying Report1 again, Report2 is still displayed and the data in the
report is incorrect.
I have dubugged the code and it all seems correct to me.When the generate
report button is clicked, the report path for Report1 is set, the new
collection of report parameters are created (which are correct) and the
datasources are setup.
The only thing that is not changing correctly is the report being rendered.
Here is some of my code
'btnGenerateReport_Click Method
rptReportViewer.LocalReport.ReportPath = MapPath("../Reports/" &
objReport.URL & ".rdlc")
rptReportViewer.LocalReport.DisplayName = objReport.Name
rptReportViewer.LocalReport.DataSources.Clear()
rptReportViewer.LocalReport.DataSources.Add(New
Microsoft.Reporting.WebForms.ReportDataSource("myDataset",
dsData.Tables(0)))
rptReportViewer.LocalReport.SetParameters(objReportParameters)
rptReportViewer.LocalReport.Refresh()
rptReportViewer.Visible = True
Is there anything else I need to do to refresh the report?
Any help would reeally be appreciated as I cannot find any help or examples
on how to do this.
Thanks
Lewis HolmesHi Lewis,
Thank you for your post.
This behavior is by design for the WebForm.ReportViewer control.
It is possible to change the DataSource of the localreport
It is not possible to change the report definition in the WebForms control
in LocalReport mode after it has been set once.
To work around the design limitation of the WebForms ReportViewer control,
you can remove the existing instance and create a new one which uses the
new report definition.
Here is a sample:
//Get the new report definition
StreamReader tr = new StreamReader( < your rdlc file path>);
string sDef = tr.ReadToEnd();
tr.Close();
//Create the new viewer and remove the old one
ControlCollection col = ReportViewer1.Parent.Controls;
int index = col.IndexOf(ReportViewer1);
ReportViewer newReportView = new ReportViewer();
col.AddAt(index, newReportView);
col.Remove(ReportViewer1);
newReportView.Visible = false;
newReportView.ProcessingMode = ProcessingMode.Local;
StringReader sr = new StringReader(sDef);
newReportView.LocalReport.LoadReportDefinition(sr);
newReportView.LocalReport.DataSources.Clear();
newReportView.LocalReport.DataSources.Add(new
Microsoft.Reporting.WebForms.ReportDataSource("DataSet1_DataTable1",
ObjectDataSource1));
newReportView.LocalReport.Refresh();
newReportView.Visible = true;
Hope this will be helpful!
Thank you!
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.

No comments:

Post a Comment