3

我有两个按钮(button1,button2)这两个按钮打开两个相同的报告,除了 report2.rdlc 有一个字符串参数

如果我首先按下 button1消息框显示参数 count = 0(如预期的那样)并且我在 reportviewer1 中显示 report1.rdlc 如果然后我按下 button2消息框再次显示参数 count = 0(我希望它显示 1)和我得到 LocalProcessingException {“尝试设置此报告中未定义的报告参数'Report2ParameterString'。”}

如果我首先按下按钮2,消息框显示参数计数 = 1(如预期的那样),并且我在 reportviewer1 中显示报告 2 如果然后我按下按钮 1 ,消息框再次显示参数计数 = 1(我希望它显示 0) 我得到报告 1 .rdlc无异常显示在reportviewer1中

我的代码是

private void report1Button_Click(object sender, EventArgs e)
    {
        reportViewer1.LocalReport.ReportPath = Application.StartupPath + "\\report1.rdlc";
        MessageBox.Show("parameters count =" + reportViewer1.LocalReport.GetParameters().Count.ToString());
        reportViewer1.LocalReport.DataSources.Clear();
        reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", reportDataTable));
        reportViewer1.RefreshReport();
    }
    private void report2Button_Click(object sender, EventArgs e)
    {
        reportViewer1.LocalReport.ReportPath = Application.StartupPath + "\\report2.rdlc";
        MessageBox.Show("parameters count =" +reportViewer1.LocalReport.GetParameters().Count.ToString());
        reportViewer1.LocalReport.SetParameters(new ReportParameter("Report2ParameterString", " testing Report2ParameterString"));
        reportViewer1.LocalReport.DataSources.Clear();
        reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", reportDataTable));
        reportViewer1.RefreshReport();
    }
4

1 回答 1

5

ReportViewer.Reset()在加载新报告之前调用。

例如:

reportViewer1.Reset();
reportViewer1.LocalReport.ReportPath = Application.StartupPath + "\\report2.rdlc";
...
于 2012-02-17T23:22:09.260 回答