问题描述
我正在开发一个Web应用程序,其中包含一个嵌入式Reportviewer控件,一个下拉列表和Ajax TabContainer. ReportViewer会为TabContainer中的每个选项卡单击或下拉列表中的每个SelectedIndexChanged事件刷新报告.我正在生成的报告是一个6个月的趋势报告,显示了从下拉列表中选择的月份和年份以来最近6个月的统计数据.我已经使用了报表参数"将选定的日期值(从下拉列表中)从代码传递到报表(.rdlc).在报表文件中使用表达式,我已经显示了通过日期值起的最近6个月的名称. C#代码如下所示.
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.
ReportParameter p1 = new ReportParameter("ReportParameter1", Session["ReportDate"].ToString());
ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { p1 });
ReportViewer1.Visible = true;
ReportViewer1.LocalReport.Refresh();
问题是我无法使用SetParameters多次设置参数.我将需要传递(a)每次更改月份的下拉列表项的参数值(b)每次更改TabContainer ActiveTab的参数(c)首次加载页面时第一次显示报告.有人可以建议如何在不同情况下为同一报表参数传递不同的值吗?
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?
推荐答案
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.
这篇关于将报告参数值从ReportViewer传递到本地报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!