Winforms Telerik从WindowsForm Codebehind向报告报告参数

Winforms Telerik从WindowsForm Codebehind向报告报告参数,winforms,telerik,report,reporting,telerik-reporting,Winforms,Telerik,Report,Reporting,Telerik Reporting,我正在开发一个Windows窗体应用程序,我想在单击按钮后将报告加载到Reportviewer中。 这是通过按下Windows窗体代码隐藏中的按钮触发的事件: private void button1_Click(object sender, EventArgs e) { Telerik.Reporting.InstanceReportSource reportSource = new Telerik.Reporting.InstanceReportSource();

我正在开发一个Windows窗体应用程序,我想在单击按钮后将报告加载到Reportviewer中。 这是通过按下Windows窗体代码隐藏中的按钮触发的事件:

    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());

        }
有没有办法在初始化组件()之后直接获取此参数? 我是否需要向报告中添加另一个事件才能访问它?如果是,哪种方式是最好的

非常感谢您的帮助。
谢谢

在报表本身的实例(而不是报表源)上设置报表的参数,例如:

        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;

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

我知道这是一个老问题,但在经历了相同的问题后,我这样做并传递了两个日期参数

      private void button1_Click(object sender, EventArgs e)
        {
        Report2 report = new Report2();
        report.ReportParameters["datefrom"].Value 
                                 =dateTimePicker1.Value;
        report.ReportParameters["dateto"].Value = dateTimePicker2.Value;

        var rSource = new InstanceReportSource();

        rSource.ReportDocument = report;
        reportViewer1.ReportSource = rSource;
        reportViewer1.RefreshReport();
    }

欢迎来到StackOverflow。最好包含描述代码的上下文以及它如何解决OP问题。请参阅以下链接,了解有关仅代码答案的社区指南-