Passing Report Paramters in through code

Posted by: orch1d on 14 September 2017, 9:45 am EST

    • Post Options:
    • Link

    Posted 14 September 2017, 9:45 am EST

    [activereports_archive]Hello everyone,

    I’m quite new to Active Reports so please forgive the rudimentary question.

    I’ve designed a report (.rdlx) with ActiveReports Report Designer. When running the report in the designer it works great. I preview the report, type in my two report parameters (StartDate and EndDate) and the correct data returns.

    I am now trying to migrate this report into my website (Visual Studio 2012) and am having some trouble passing report parameters into the report. How do I reference and pass a value into a report parameter? For reasons specific to my project, I am trying to do this through code and not through a front end. Here’s what I have so far:

    [vb]

    'declare page report

    Dim rpt As New GrapeCity.ActiveReports.PageReport()

    'Load rdlx report I designed in ActiveReports Report Designer

    rpt.Load(New System.IO.FileInfo(Server.MapPath("") + "\Reports\LeaveOfAbsence_workingParams.rdlx"))

        'Declare report parameter
        Dim startDate As New GrapeCity.ActiveReports.PageReportModel.ReportParameter
        Dim endDate As New GrapeCity.ActiveReports.PageReportModel.ReportParameter
    
        'this value returns the name of the first parameter I created in ActiveReports Report Designer
        Dim sParamName As String = rpt.Report.ReportParameters(0).Name
        '> StartDate
        
        startDate = rpt.Report.ReportParameters(0)
        endDate = rpt.Report.ReportParameters(1)
        
        'How do I give startDate and endDate a value to pass in?
        'startdate.value isn't an option
     
        'run report
        rpt.Run()
        
        'Export PDF of report
        Dim pdfExport1 As GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport = New GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport()
        pdfExport1.Export(rpt.Document, Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/output/test.pdf")
    

    [/vb]

    Can anyone else me pass in my own date values from the code?

    Thanks so much![/activereports_archive]

  • Posted 14 September 2017, 9:45 am EST

    [activereports_archive]Hello,

    You can pass the values to report parameters using the following code :

    [vb]Dim rpt As New GrapeCity.ActiveReports.PageReport()

    rpt.Load(New System.IO.FileInfo(Server.MapPath("") + "\PageReport1.rdlx"))

    If rpt.Report.ReportParameters(0).DefaultValue.Values.Count > 0 Then

    rpt.Report.ReportParameters(0).DefaultValue.Values(0) = "ReportParameter"

    Else

    rpt.Report.ReportParameters(0).DefaultValue.Values.Add("ReportParameter")

    End If

    rpt.Run()

    WebViewer1.Report = rpt[/vb]

    Regards

    Abdias

    [/activereports_archive]

  • Posted 14 September 2017, 9:45 am EST

    [activereports_archive]Thank you very much. I didn’t think to use default values. This is working perfectly.[/activereports_archive]

  • Posted 24 June 2020, 8:37 pm EST

    This the code for VB .net how can i do in c#

  • Posted 26 June 2020, 1:12 am EST

    Hello,

    Please refer to the following line of code:

    GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport();
     rpt.Load(new System.IO.FileInfo(@"\ARWeb_NetCore\ARWeb_NetCore\reports\rdlreport1.rdlx"));
    foreach (GrapeCity.ActiveReports.PageReportModel.ReportParameter parameter in rpt.Report.ReportParameters)
     {
                    if (parameter.Name == "ReportParameter1")
                    {
    parameter.DefaultValue.Values.Clear();
    parameter.DefaultValue.Values.Add("Test & Test");
    }
           }
    

    Thanks,

    Mohit

Need extra support?

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

Learn More

Forum Channels