http://www.telerik.com/community/forums/reporting/telerik-reporting/saving-report-criteria.aspx#1736100
Does the Telerik Report Viewer expose an event or object which would allow me to grab these values? The only workaround I could see was to grab the data from the drop downs themselves. Using jQuery I wrote this as a simple test on a button click:
$("iframe[id$='ParametersArea']").contents().find("select").each(function (index) {
alert( $(this).val() + " | disabled: " + $(this).is(':disabled') + " | id: " + this.id);
});
The only other option is to build my own Parameter sections from scratch (20 reports with up to 8 parameters each, oh joy).
Please let me know if anything has changed in the past to years in this regard,
Thank you
4 Answers, 1 is accepted
For your scenario our suggestion is to create a base class for handling ItemDataBinding and collect the derived reports' parameters. Check out the following code snippet that illustrates the suggested approach:
public class HistoryReport : Telerik.Reporting.Report { public HistoryReport() : base() { this.ItemDataBinding +=
new EventHandler(HistoryReport_ItemDataBinding); } void HistoryReport_ItemDataBinding(object sender, EventArgs e) { var parameterHistory = new Dictionary<string, object>(); foreach (var parameter in base.ReportParameters) { parameterHistory.Add(parameter.Name, parameter.Value); }
var name = base.Name; }}Peter
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
Thank you for your quick reply. The only issue I have is that if the code you sent works, I can only store the current parameter settings if they do not require the report to be refreshed (auto-postback). In other words, the user selects the filters they want and has to click preview (at which point I will temporarily store the reports settings) and then the user clicks Save Settings. If the user does not preview the report before saving it, the settings would not be stored.
I'm just a little curious though why there are no hooks into the ReportViewer control for any of this. But I know that's beside the point.
I'll do some tests and see if I can get it to work.
Thanks again,
Paul
The Report Parameter area does not expose any events because currently provides out-of-the-box UI support that covers 98% of the user cases.
Regards,Peter
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
Hi,
I came across another solution. There might not be an event that is exposed, but Reporting commicates through a controller.
It uses Json to pass the parameters. This includes any changes the user made.
We can override ExecuteAsync to intercept the Json and store the parameters for later use.
public async override Task<HttpResponseMessage> ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken){ string contentString = await controllerContext.Request.Content.ReadAsStringAsync(); if (!string.IsNullOrEmpty(contentString)) await SaveReportSettingsAsync(contentString); return await base.ExecuteAsync(controllerContext, cancellationToken);}
The next function uses Newtonsoft.Json to process the message and extract the parameters. The name of the report is passes in the Json property "report". The parameters are passes through the property parameterValues. If both are present, I go ahead and call SaveReportSettingsAsync.
private async Task SaveReportSettingsAsync(string contentString){ var content = JObject.Parse(contentString); if (content.ContainsKey("report") && content.ContainsKey("parameterValues")) { var parameters = (JObject)content["parameterValues"]; if (parameters.Count != 0) { string settingValue = parameters.ToString(Newtonsoft.Json.Formatting.None); string reportId = content["report"].Value<string>(); await SaveReportSettingsAsync(reportId, settingValue); } }}
private async Task SaveReportSettingsAsync(Guid reportId, string settings){ // Save the settings to a database, file or whatever is appropriate.}
Next, adjust the code that returns the Report class. In my case this was inside the IReportResolver implementation.
public ReportSource Resolve(string report){ Report report = CreateMyReport(report); var reportSource = new InstanceReportSource { ReportDocument = report }; ProcessParameters(report.ReportParameters); return new InstanceReportSource { ReportDocument = reportInstance };}private void ProcessParameters(ReportParameterCollection parameters, string settingValue){ foreach (var entry in JObject.Parse(settingValue)) { object value; switch (entry.Value.Type) { case JTokenType.Integer: value = entry.Value.ToObject<int>(); break; case JTokenType.Float: value = entry.Value.ToObject<double>(); break; case JTokenType.String: value = entry.Value.ToObject<string>(); break; case JTokenType.Boolean: value = entry.Value.ToObject<bool>(); break; case JTokenType.Date: value = entry.Value.ToObject<DateTime>(); break; case JTokenType.Guid: value = entry.Value.ToObject<Guid>(); break; case JTokenType.Null: value = null; break; default: throw new NotSupportedException($"The Json type {entry.Value.Type} is not supported.)); } parameters[entry.Key].Value = value; }}
I hope is of help to someone else.
Marcel