.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"));



Open in new window

Who is Participating?
tknudsen-qecConnect With a Mentor Author Commented:
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...
Alfred A.Commented:
Try to add this after your code snippet:

you close the report viewer after displaying the report and load as a fresh viewer for the filtered data.
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:
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.
Try the following function
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.

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.