.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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
tknudsen-qecAuthor 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.