0

ボタンをクリックした後にレポートを Reportviewer にロードしたい Windows Forms アプリケーションに取り組んでいます。これは、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();

}

問題は、レポートビューアを更新する前に追加したパラメータにアクセス/取得する方法がわからないことです。レポートはすでにデータソースを設定しています。これが重要かどうかはわかりません。これは私が今持っているものです。私はすべてを試しましたが、それ以上進んでいません。

        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(); の直後にこのパラメータを取得する方法はありますか? ? レポートにアクセスするには、レポートに別のイベントを追加する必要がありますか? はいの場合、これを行うための最良の方法はどれですか?

どんな助けでも非常に感謝しています。ありがとうございました

4

2 に答える 2

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;

デバッガーを使用して値を確認できます。

于 2013-05-15T20:12:26.073 に答える