I have looked through the Telerik documentation and I do not see how to do this.
9 Answers, 1 is accepted
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.
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.
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)
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.
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();
}
}
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.
Hi i am getting similar problem, i send in the parameter, but value never gets there...
I am using latest Newtonsoft.Json
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"
/>
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" />