如何将参数传递给Reportviewer?

时间:2022-04-05 22:55:41

I am trying to create report for TOP (according to user provide say 10,100,200..) products. I am 90% success with it. Now, I am finding difficulties to show this numbers to Report header. So, my report header is saying Top Products, now I want to make this dynamic, saying Top 100 Products, Top 200 Products.

我正在尝试为TOP创建报告(根据用户提供的说10,100,200 ..)产品。我用它取得了90%的成功。现在,我发现很难将这些数字显示给Report头。所以,我的报告标题是Top Products,现在我想让这个充满活力,说100强产品,200强产品。

I AM USING VS 2008.

我正在使用VS 2008。

For this, I created parameter in ReportViewer. I tried this code in Page_Load event ;

为此,我在ReportViewer中创建了参数。我在Page_Load事件中尝试了这段代码;

 protected void Page_Load(object sender, EventArgs e)
{
    ReportDataSource rds = new ReportDataSource("SP_GetProductsbySales_DataSet");
    //ReportViewer1.ServerReport.ReportPath = "Report1.rdlc";
    ReportViewer1.LocalReport.ReportPath = "Report1.rdlc";
    ReportParameter[] param = new ReportParameter[1];
    param[0] = new ReportParameter("top", "100");

    ReportViewer1.ServerReport.SetParameters(param);
    ReportViewer1.ServerReport.Refresh();
}

but getting error saying : The source of the report definition has not been specified.

但得到错误说:尚未指定报告定义的来源。

How can I accomplish this one? I tried to google as well as watched some videos, but still I am not getting any idea.

我怎样才能完成这个?我试图谷歌以及观看一些视频,但我仍然不知道。

Thanks.

谢谢。

2 个解决方案

#1


0  

Please set data source

请设置数据源

       ReportViewer1.LocalReport.DataSources.Clear();

       ReportViewer1.LocalReport.DataSources.Add(rds);

#2


0  

You can set an expression in your report to show the value.

您可以在报表中设置表达式以显示值。

The expression would be as follows:

表达方式如下:

="Top " & Parameters!top.Value & " Products"

#1


0  

Please set data source

请设置数据源

       ReportViewer1.LocalReport.DataSources.Clear();

       ReportViewer1.LocalReport.DataSources.Add(rds);

#2


0  

You can set an expression in your report to show the value.

您可以在报表中设置表达式以显示值。

The expression would be as follows:

表达方式如下:

="Top " & Parameters!top.Value & " Products"