3

Problem: I am trying to pass a Report Parameter value from the query string on the page to my report that already has the parameter defined. I just can't seem to get the value passed all the way to the report.

        Telerik.Reporting.Report report = new MyCustomReportLibrary.TelerikReport();
        report.ReportParameters["parameterName"].Value = Request.QueryString["Id"];

        ReportViewer.Report = report;

This syntax above is fine but when the variable "report" is created by the TelerikReport() constructor it doesn't have a value for the parameter yet and when I set it after the fact it doesn't seem to matter. Even if I try to call a ReportViewer.RefreshReport().

Places I have looked:

Thanks for the help,

Chris

3 Answers3

2

I was able to get it to work by altering the Contructor for MyCustomReportLibrary.TelerikReport. Hope this helps anyone looking for the answer.

Much like this example Telerik Forums | Pass Report parameters from Rad window to a telerik report

Telerik Report Code (TelerikReport.cs)

    public TelerikReport(int Id)
    {
        //
        // Required for telerik Reporting designer support
        //
        InitializeComponent();

        this.ReportParameters["parameterName"].Value = Id;
    } 

ASP.Net Page Code (ReportViewerPage.cs)

    protected void Page_Load(object sender, EventArgs e)
    {
        Report raReport = new TelerikReport(Request.QueryString["Id"] as int);
        ReportViewer1.Report = raReport;
    }
1

I will offer another answer that is simple and works for MVC (Q3 2015).

MVC

@(Html
.TelerikReporting()
.ReportViewer()
.Id("reportViewer1")
.ServiceUrl(Url.Content("/Controllers/Reports/"))

//Setting the ReportSource Parameters overrides the default specified in the report.
.ReportSource(new TypeReportSource() { TypeName = @ViewBag.TypeName, Parameters = { new Parameter("startDate", Request.QueryString["startDate"]) } }) 
//To make the query string parameter optional, try:
//.ReportSource(new TypeReportSource() { TypeName = @ViewBag.TypeName, Parameters = { Request.QueryString["startDate"] != null ? new Parameter("startDate", Request.QueryString["startDate"]) : new Parameter() } })

.ViewMode(ViewMode.Interactive)
.ScaleMode(ScaleMode.Specific)
.Scale(1.0)
.PersistSession(false)
.PrintMode(PrintMode.AutoSelect)
)

The Report is nothing special.

public TelerikApplicationReport()
{
    InitializeComponent();
}
Onosa
  • 1,275
  • 1
  • 12
  • 28
0

This is another example. Pass parameters directly to the report.

In Asp.net page

protected void Button1_Click(object sender, EventArgs e)
        {
            var instanceReportSource = new Telerik.Reporting.InstanceReportSource();
            instanceReportSource.ReportDocument = new SampleReport(TextBox1.Text);
            this.ReportViewer1.ReportSource = instanceReportSource;
        }

In report

public partial class SampleReport : Telerik.Reporting.Report
    {
        public SampleReport(string invoiceNumber)
        {           
            InitializeComponent();


        }
    }
Thinira
  • 361
  • 3
  • 8