Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing a web app containing an embedded Reportviewer control, a dropdownlist and Ajax TabContainer. The ReportViewer refreshes the report for every tab click in the TabContainer or for every SelectedIndexChanged event of the dropdownlist. The report I am generating is a 6-month trending report displaying statistical data for the last 6 months from the month and year selected in the dropdownlist. I have used Report Parameter to pass the selected date value (from dropdownlist) from the code to the Report (.rdlc). Using Expressions in report file I have displayed last 6 months names from the passing date value. The C# code looks like this.
C#
ReportParameter p1 = new ReportParameter("ReportParameter1", Session["ReportDate"].ToString());

ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { p1 });
ReportViewer1.Visible = true;

ReportViewer1.LocalReport.Refresh();

The problem is I am not able to set parameters more than once using SetParameters. I will need to pass the parameter value for (a)Everytime the dropdownlist item for month is changed (b) Everytime the TabContainer ActiveTab is changed (c) When the page loads for first time displaying the report for first time. Can someone advise how to pass different values for the same report parameter under different scenarios? Can we change the parameter value passed once it has been set using SetParameters?
Posted
Updated 5-Jan-11 18:57pm
v3

That's not a big deal, you just change the session value based on your conditions (a),(b)&(c) dynamically & then send the session value to reportviewer's parameter.

For your information

Using report parameters in local mode[^]

In this example parameter value changing based on checkbox's checked status. Let us know if you still have any doubt.
 
Share this answer
 
Comments
tjkota 6-Jan-11 11:44am    
hi, thanks Raja for your input. Can you elaborate on 'change session value based on your conditions and send the session value to reportviewer's parameter?' How can send the session value? By using SetParameters again?
thatraja 6-Jan-11 11:55am    
Hi, did you saw that link which I have mentioned in my answer? actually better include your code in your question.
tjkota 6-Jan-11 11:58am    
hi Raja, Actually your solution worked! I thought it is forbidden to use SetParameters in multiple places. I included this code in SelectedIndexChanged event handler:
Session["ReportDate"] = ddlMonth.SelectedIndex + 1 + "-01-" + ddlYear.SelectedValue;
//Populate Report Paramater for passing current date (month)
ReportParameter p1 = new ReportParameter("ReportParameter1", Session["ReportDate"].ToString());
ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { p1 });
ReportViewer1.LocalReport.Refresh();

And includes same lines of code on Page Not Postback (to display months in report when loading for first time). It works like magic! Thanks a ton for your solution.
thatraja 6-Jan-11 12:10pm    
That's it man, good. BTW are you calling this code in 3 sections[I mean your conditions (a),(b)&(c)] right? So make it as a method with parameter & call it in three sections. It will reduce the code.
tjkota 6-Jan-11 12:51pm    
Great suggestion! Will do.
ReportParameter p1 = new ReportParameter("ReportParameter1", Session["ReportDate"].ToString());

ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { p1 });
ReportViewer1.Visible = true;

ReportViewer1.DataBind(); // Added

ReportViewer1.LocalReport.Refresh();


Try It because yours report is working for first time. I think by the second time you are just refreshing report rather then binding the data or parameter again.
 
Share this answer
 
Comments
tjkota 6-Jan-11 11:42am    
hello, I tried ReportViewer1.Databind() every time I captured a new value for Session["ReportDate"]. This does not help bind the parameter value.
Silver Lightning 9-Jul-12 2:40am    
is this issue resolved?
tani12345 21-Sep-14 12:41pm    
How to pass multiple parameter
Member 10204631 4-Jan-17 10:05am    
There is not .DataBind() assoicated with the report viewer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900