.NET ReportViewer

I'm using a ReportViwer.  It works fine the first time it binds data, but if the criteria (parameters or FilterExpression) change on a postback, the data pulled doesn't change accordingly.

My changing paramaters are datevariable1 and datevariable2, which change depending on user input.

Rather than keep smashing my forehead off my desk I figured I might as well see if any EXPERTS had a notion what I'm doing wrong.

Please assist!


ReportViewer ReportViewer1 = new ReportViewer();
ReportViewer1.LocalReport.ReportPath = "Report1.rdlc";

ObjectDataSource ODS = new ObjectDataSource("GraphTest.ValuesByDateDataSetTableAdapters.vValuesByDateTableAdapter", "GetDataByDateRange");
ReportDataSource RDS = new ReportDataSource("ValuesByDateDataSet_vValuesByDate", ODS);

	
ODS.SelectParameters.Add("Start", datevariable1.ToString("d"));
ODS.SelectParameters.Add("End", datevariable2.ToString("d"));

ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(RDS);

PlaceHolder1.Controls.Add(ReportViewer1);

Open in new window

LVL 3
tknudsen-qecAsked:
Who is Participating?
 
tknudsen-qecConnect With a Mentor Author Commented:
Alfred1:
Thanks for your reply.

I had tried every combination of Refresh, Reset, Databinds I can think of on the ReportViewer and ODS.

Oddly enough, I found a workaround.  Instead of instantiating the object in the code, I create the blank version of the ReportViewer on the design view (drag it on and leave it alone).  The rest of the code stays intact and suddenly it works.

I don't know enough about the ASP life cycle to know why that works but obviously something is disconnecting/rebuilding properly on reposts when the object exists in the design view.

Very likely I could have accomplished the same goal using something other than page_load...
0
 
Alfred A.Commented:
Try to add this after your code snippet:

ReportViewer1.LocalReport.Refresh()
0
 
samsymonCommented:
you close the report viewer after displaying the report and load as a fresh viewer for the filtered data.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
tknudsen-qecAuthor Commented:
samsymon,
Thanks kindly for your reply.  I'm not clear on whether your comment was a suggestion on what I'm doing wrong or what I could do right, sorry :(

I seem to have found a workaround solution for now however.  

Thanks again.
0
 
greatsubashCommented:
Try the following function
ReportViewer1.RefreshReport();
0
 
tknudsen-qecAuthor Commented:
Hi greatsubash,

Thanks for your reply.  For the webforms version of the ReportViewer class, RefreshReport is an event, not a method, and I don't see how I would handle it to fix this.

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.