This is a migrated thread and some comments may be shown as answers.

Passing value to report parameter

9 Answers 1402 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 2
Brian asked on 19 Nov 2014, 05:19 PM
I have a report viewer on my asp.net page and its ReportSource.TypeName is set to the .vb file of my report.  My .vb report has a parameter and I need to pass in a value to it.  The report viewer has its own parameters but these seem to be different than the report's parameters as compiled in the .vb code.  How do I pass a value to the report?  

I have looked through the Telerik documentation and I do not see how to do this.  

9 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 21 Nov 2014, 12:34 PM
Hello Brian,

Values can be passed to the report parameters via the TypeReportSource.Parameters collection. For more information and samples, please refer to the TypeReportSource Class article.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Brian
Top achievements
Rank 2
answered on 22 Nov 2014, 09:21 AM
Nasko,

Thank you for this information.  I feel like I must be missing something fundamental as this is not working for me.  

There are parameters in the report viewer and there are parameters in the report designer.  I can not seem to assign values to parameters in the report viewer (with TypeReportSource.Parameters) and then have the content generated from the report designer "see" those values and use them.

For example, I'm trying to pass an "Account" value.  If I create an Account parameter in the viewer and the designer, the designer ignores the value I set in the viewer.  If I only have an Account parameter in the viewer and remove it from the designer, then the report errors because it does not have an Account parameter.  I have no problem creating and setting a parameter value in the viewer but I can't seem to get any external values into the report designer and use them.  
0
Brian
Top achievements
Rank 2
answered on 22 Nov 2014, 11:25 AM
Nasko,

To clarify, here is the code I'm using in the Load event on the page.  rptInvoice is the viewer control.

typeReportSource.TypeName = GetType(Invoice).AssemblyQualifiedName
typeReportSource.Parameters.Add(New Telerik.Reporting.Parameter("Account", "CustomerNameHere"))
rptInvoice.ReportSource = typeReportSource

Within the Invoice designer, whether I do or do not have an Account parameter, the value is not set.  If I set a default value in the designer, that value is used.  If I do not include a parameter in the designer, I get an error that there the Account parameter is missing (it's used in the SQL to generate the invoice)
0
Nasko
Telerik team
answered on 26 Nov 2014, 03:45 PM
Hello Brian,

Check the attached project which is demonstrating how to pass a value to the report parameters in your report.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
JOSE BERNARDO
Top achievements
Rank 1
answered on 12 Mar 2015, 05:18 AM
Hello , 
I have the same issue related to this post but for MVC 4 . I'm using the ReportViewer Widget and  VS reports . I tried to replicate the code in the attached project but I think I'm missing something since I can get passed the parameter to report. Please see code below and let me know If there is something else I need to do. 

Thanks in Advance.

//View
@model RH4000.Models.Reporting.ReportViewerViewModel
@{
    Layout = "~/Views/Shared/_ReportingLayout.cshtml";
}
@(Html.TelerikReporting().ReportViewer()
        .Id("reportViewer")
        .ServiceUrl("/api/reports/")
        .TemplateUrl(Model.TemplateUri)
        .ReportSource(Model.TReportSource)
        .ViewMode(ViewModes.INTERACTIVE)
        .ScaleMode(ScaleModes.SPECIFIC)
        .Scale(1.0)
        //.PersistSession(false)
 
)


//Controller
public
ActionResult Index()
       {
           ReportViewerViewModel model = (ReportViewerViewModel)TempData["ReportSourceModel"];
           return View(model);
       }
 
       [HttpPost]
       public ActionResult PrePayrollMovements(FormCollection collection)
       { 
           TempData["ReportSourceModel"] = CreateReportSource(typeof(PreMovementsReport));
           return RedirectToAction("Index", "Report");
       }
 
       private static ReportViewerViewModel CreateReportSource(Type objType)
       {
           var reportSourceModel = new ReportViewerViewModel();
           reportSourceModel.TemplateUri = ConfigurationManager.AppSettings["ReportingTemplate"] ?? "/Content/templates/telerikReportViewerTemplate-8.2.14.1204.html";
           reportSourceModel.TReportSource = new TypeReportSource();           
           reportSourceModel.TReportSource.TypeName = objType.AssemblyQualifiedName;
           reportSourceModel.TReportSource.Parameters.Add(new Telerik.Reporting.Parameter("PeriodID", "ab6f36d6-1831-4711-ba73-704501470bc7"));          
           return reportSourceModel;
       }




//Report Api
public class ReportsController : ReportsControllerBase
    {
        protected override IReportResolver CreateReportResolver()
        {
            var reportsPath = HttpContext.Current.Server.MapPath("~/Reports");
            return new ReportTypeResolver().AddFallbackResolver(new ReportTypeResolver());           
        }
        protected override ICache CreateCache()
        {
            return Telerik.Reporting.Services.Engine.CacheFactory.CreateFileCache();
        }
    }

0
Nasko
Telerik team
answered on 16 Mar 2015, 03:08 PM
Hello Jose,

There is a known issue caused by external libraries where the parameter values will not be passed from the report viewer to the report using the HTML5 Report Viewer in some scenarios. This issue is caused by using an old version of the Newtonsoft.Json assembly. Please open your project and check for updates for the Newtonsoft.Json.dll via NuGet.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Boris
Top achievements
Rank 1
answered on 14 Sep 2018, 09:08 PM

Hi i am getting similar problem,  i send in the parameter, but value never gets there...

I am using latest Newtonsoft.Json

0
AQEEL KHAN
Top achievements
Rank 1
Veteran
answered on 11 Aug 2020, 12:13 AM

may i know how to do it in Blazor ? i am using store procedure which have parameters how can i pass that to report ?

following code giving me error.

<ReportViewer ViewerId="rv1"
              ServiceUrl="https://localhost:44331/api/reports"
              ReportSource="@(new ReportSourceOptions()
                            {
                                Report = "rp_TrailBalance.trdp",
                                Parameters = {
                                    new KeyValuePair<string, object>("Telerik.Reporting.SqlDataSourceParameter.PlanID",3),
                                    new KeyValuePair<string, object>("Telerik.Reporting.SqlDataSourceParameter.startDate","2020-01-01"),
                                    new KeyValuePair<string, object>("Telerik.Reporting.SqlDataSourceParameter.endDate","2020-12-31")
                                    }
                            })"
              ScaleMode="@(ScaleMode.Specific)"
              Scale="1.0" />
0
AQEEL KHAN
Top achievements
Rank 1
Veteran
answered on 11 Aug 2020, 12:39 AM

Tried Following with no error but parameter is not working ... do i have to remove parameter from report which have default value for preview ?

 

<ReportViewer ViewerId="rv1"
              ServiceUrl="https://localhost:44331/api/reports"
              ReportSource="@(new ReportSourceOptions()
                            {
                                Report = "rp_TrailBalance.trdp",
                                Parameters = new Dictionary<string, object>()
                                {
                                    { "@PlanID","4" },
                                    { "@startDate","2020-01-01" },
                                    { "@endDate","2020-12-31" }
                                }
                            })"
              ScaleMode="@(ScaleMode.Specific)"
              Scale="1.0" />

 

Tags
General Discussions
Asked by
Brian
Top achievements
Rank 2
Answers by
Nasko
Telerik team
Brian
Top achievements
Rank 2
JOSE BERNARDO
Top achievements
Rank 1
Boris
Top achievements
Rank 1
AQEEL KHAN
Top achievements
Rank 1
Veteran
Share this question
or