How to pass values from c# wpf code to a parameter of a report

Posted by: eariza on 23 November 2022, 8:06 pm EST

    • Post Options:
    • Link

    Posted 23 November 2022, 8:06 pm EST

    Hello ! I’ve tried to pass values from c# wpf code to a parameter of a report. But all the options the tool provide me are readonly. I’ve seen this example but in this version doesn’t works:

    var report = new MyReport();
    report.Parameters["Parm1"].PromptUser = false;
    report.Parameters["Parm1"].Value = someVariable;
    report.Parameters["Parm2"].PromptUser = false;
    report.Parameters["Parm2"].Value = someVariable2.ToString("M-d-yyyy");
    report.Run();

    I reference my report this way:

    [code]string file_name = @“…....\FD\RdlReport1.rdlx”;

    GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(file_name));

    GrapeCity.ActiveReports.Document.PageDocument pageDocument = new GrapeCity.ActiveReports.Document.PageDocument(pageReport);

    GrapeCity.ActiveReports.Viewer.Win.Viewer viewer1 = new GrapeCity.ActiveReports.Viewer.Win.Viewer();

    pageReport.Parameters[“ou”].DefaultValues = “aa”;[/code]


    In the last line i try to put values but doesn’t works i hope you can help me thank you!

  • Posted 27 November 2022, 9:54 pm EST

    Hi Esteban,

    You can pass your parameters through the ‘PageReport.Document.Parameters’ class.

    Now to invoke/run the report you can use PageReport.Run() method this will render the report which you can access using ‘PageReport.Document’.

    You can use this PageDocument to preview the rendered report in a viewer or export this document to different file formats.

    Please refer to the following code snippet for the same.

    string file_name = @".\RdlReport1.rdlx";
    GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(file_name));
    GrapeCity.ActiveReports.Document.PageDocument pageDocument = new GrapeCity.ActiveReports.Document.PageDocument(pageReport);
    pageDocument.Parameters["ou"].CurrentValue = "aa"; // Assigning a value to report's parameter through code. 
    arViewer.LoadDocument(pageDocument);  

    Please find attached a sample for the same.

    Regards,

    Anand

    WPFViewer (1).zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels