2013-05-06 104 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; 

您可以使用調試器查看該值。