2013-05-06 108 views
0

我正在使用Windows窗体应用程序,在窗体应用程序中单击按钮后,要将报告加载到报告查看器中。 这是获取由代码按下按钮上的Windows窗体的背后触发事件:Telerik将WindowsForm Codebehind中的参数报告到报告

private void button1_Click(object sender, EventArgs e) 
{ 

    Telerik.Reporting.InstanceReportSource reportSource = new 
    Telerik.Reporting.InstanceReportSource(); 
    reportSource.ReportDocument = new Reportlibrary.Report1(); 

    reportSource.Parameters.Add(new Telerik.Reporting.Parameter("OrderNumber","123456789")); 

    reportViewer1.ReportSource = reportSource; 
    reportViewer1.RefreshReport(); 

} 

现在的问题是,我不知道我怎么能访问/获取我刷新之前添加参数Reportviewer。 报告已经设置了数据源。我不知道这是否重要。 这就是我现在所拥有的。我试过了所有的东西,我只是没有进一步。

 public Report1() 
     { 
      InitializeComponent(); 

      Position[] all = new Position[]{ 

       new Position("Test", "Test","test"), 

      }; 

      this.DataSource = all; 

      MessageBox.Show("Number: " + 
      this.Report.ReportParameters["OrderNumber"].Value.ToString()); 

     } 

有没有什么办法让InitializeComponent(); ? 我是否需要向报告添加其他事件才能访问它?如果是,哪一个是最好的办法呢?

任何帮助非常apreciated。 谢谢

回答

0

组的报告对报告本身(而不是报表源)的实例参数,如:

 TopPageViews report = new TopPageViews(); 
     report.ReportParameters["StartDate"].Value = new DateTime(2013, 3, 1); 
     report.ReportParameters["EndDate"].Value = new DateTime(2013, 3, 1); 

     InstanceReportSource reportSource = new InstanceReportSource(); 
     reportSource.ReportDocument = report; 

     this.reportViewer1.ReportSource = reportSource; 
     this.reportViewer1.RefreshReport(); 

在您的报告中的构造,在InitializeComponent之后,订阅处理程序到ItemDataBinding事件:

this.ItemDataBinding += TopPageViews_ItemDataBinding; 

而在你处理,你可以得到价值,你通常会:

DateTime startDateParm = (DateTime)this.ReportParameters["StartDate"].Value; 

您可以使用调试器查看该值。