BoldSign®Effortlessly integrate e-signatures into your app with the BoldSign® API. Create a sandbox account!
Hello,
How to I get report parameters from the ReportViewer control after clicked on View Report button. I cannot find a server event for "View Report" button
<form id="form1" runat="server"> <asp:ScriptManager runat="server" /> <div id="reportviewer"> <ej:ReportViewer ID="viewer" runat="server" PrintMode="false"></ej:ReportViewer> </div> </form>
Code Behind:
viewer.Visible = true; var rpt = new AnnualWorkloadRep2014(2014, 53); // I want to pass dynamic values from report viewer's parameter control viewer.ProcessingMode = Syncfusion.JavaScript.ReportViewerEnums.ProcessingMode.Local; viewer.ReportPath = rpt.ReportPath; viewer.ReportServiceUrl = "api/reportapi"; viewer.DataSources = rpt.SfGetDataSources(); var caseYear = new Syncfusion.JavaScript.Models.ReportViewer.ReportParameter() { Name = "CaseYear", Prompt = "Case Year", Labels = null, Values = new List<string> { "2014" }, Nullable = false }; var countyId = new Syncfusion.JavaScript.Models.ReportViewer.ReportParameter() { Name = "CountyId", Prompt = "County ID", Labels = null, Values = new List<string> { "53" }, Nullable = false }; var list = new List<Syncfusion.JavaScript.Models.ReportViewer.ReportParameter>(); list.Add(caseYear); list.Add(countyId); viewer.Parameters.AddRange(list);Hope I described it clearly.Appreciate your help.
How to I get report parameters from the ReportViewer control after clicked on View Report button. I cannot find a server event for "View Report" button |
We can get the available list of report parameters and its values in the script block after clicked the “View Report button” through click event as shown in below code snippet. Also, the dynamically assigned parameter values should be passed into the reportviewer control through “ajax call” as provided in the below sample.
| |
I want to pass dynamic values from report viewer's parameter control |
The dynamic parameter values can be handled at code behind (WebApi controller) to filter the RDLC datasource values and assigned into the report parameters as shown in below code snippet.
However, we have prepared a sample based on your scenario and it can be downloaded from the below link.
|
Hello,
I have tried out your code and got it to work, but I came up another problem that how do I pass parameters from Report Initial Load because the Get Method would not execute when report loading. I don't want to hard-code the values when report loaded the first time.
Code Behind:
public class ReportApiController : ApiController, IReportController
{
object reportDataSources;
DataTable rs;
DataTable rs1;
DataTable rs2;
// GET api/<controller>
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/<controller>/5
public string Get(string id)
{
return "value";
}
// POST api/<controller>
public void Post([FromBody]string value)
{
}
// PUT api/<controller>/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/<controller>/5
public void Delete(int id)
{
}
//Post action for processing the rdl/rdlc report
public object PostReportAction(Dictionary<string, object> jsonResult)
{
//if (jsonResult.ContainsKey("dataSources"))
//{
// reportDataSources = jsonResult["dataSources"];
// var a = JArray.Parse(reportDataSources.ToString());
// // var b = (JObject)JsonConvert.DeserializeObject(reportDataSources.ToString());
// rs = JsonConvert.DeserializeObject<DataTable>(a[0]["value"].ToString());
// rs1 = JsonConvert.DeserializeObject<DataTable>(a[1]["value"].ToString());
// rs2 = JsonConvert.DeserializeObject<DataTable>(a[2]["value"].ToString());
//}
if (jsonResult.ContainsValue("GetDataSourceCredential") && jsonResult.ContainsKey("params"))
{
System.Web.HttpContext.Current.Items.Add("parakey", jsonResult["params"]);
}
return ReportHelper.ProcessReport(jsonResult, this);
}
//Get action for getting resources from the report
[System.Web.Http.ActionName("GetResource")]
[AcceptVerbs("GET")]
public object GetResource(string key, string resourcetype, bool isPrint)
{
return ReportHelper.GetResource(key, resourcetype, isPrint);
}
/// <summary>
/// Method will be called when initialize the report options before start processing the report
/// Report Initialization method that is triggered when report begins to be processed.
/// </summary>
/// <param name="reportOptions">The ReportViewer options.</param>
public void OnInitReportOptions(ReportViewerOptions reportOptions)
{
//You can update report options here
//List<Syncfusion.Reports.EJ.ReportParameter> parameters = new List<Syncfusion.Reports.EJ.ReportParameter>();
//parameters.Add(new Syncfusion.Reports.EJ.ReportParameter() { Prompt= "Comments", Nullable=true, Name = "Comments", Labels = new List<string>() { "Comments" } });
//reportOptions.ReportModel.Parameters = parameters;
}
/// <summary>
/// Method will be called when reported is loaded
/// Report loaded method that is triggered when report and sub report are loaded.
/// </summary>
/// <param name="reportOptions">The ReportViewer options.</param>
public void OnReportLoaded(ReportViewerOptions reportOptions)
{
////You can update report options here
////Adds data sources to report model.
//reportOptions.ReportModel.DataSources.Clear();
var rpt = new AnnualWorkloadRep2014(2014, 53);
var ds = new DataSet();
ds = rpt.GetDataSource();
var parameters = new List<Syncfusion.Reports.EJ.ReportParameter>();
if (System.Web.HttpContext.Current.Items.Contains("parakey"))
{
parameters = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<List<Syncfusion.Reports.EJ.ReportParameter>>(System.Web.HttpContext.Current.Items["parakey"].ToString());
System.Web.HttpContext.Current.Items.Remove("parakey");
}
// Parameters variable always Zero for the initial loaded.
reportOptions.ReportModel.Parameters = parameters;
if (parameters != null && parameters.Count > 0)
{
reportOptions.ReportModel.DataSources.Clear();
reportOptions.ReportModel.DataSources.Add(new Syncfusion.Reports.EJ.ReportDataSource { Name = "dsDeathInvestigatedCertified", Value = ds.Tables["DeathInvestigatedCertified"] });
reportOptions.ReportModel.DataSources.Add(new Syncfusion.Reports.EJ.ReportDataSource { Name = "dsSIDS", Value = ds.Tables["SIDSTable"] });
reportOptions.ReportModel.DataSources.Add(new Syncfusion.Reports.EJ.ReportDataSource { Name = "dsJD", Value = ds.Tables["JDCases"] });
reportOptions.ReportModel.DataSources.Add(new Syncfusion.Reports.EJ.ReportDataSource { Name = "dsFetalDeaths", Value = ds.Tables["FetalDeaths"] });
}
else
{
reportOptions.ReportModel.DataSources.Clear();
reportOptions.ReportModel.DataSources.Add(new Syncfusion.Reports.EJ.ReportDataSource { Name = "dsDeathInvestigatedCertified", Value = ds.Tables["DeathInvestigatedCertified"] });
reportOptions.ReportModel.DataSources.Add(new Syncfusion.Reports.EJ.ReportDataSource { Name = "dsSIDS", Value = ds.Tables["SIDSTable"] });
reportOptions.ReportModel.DataSources.Add(new Syncfusion.Reports.EJ.ReportDataSource { Name = "dsJD", Value = ds.Tables["JDCases"] });
reportOptions.ReportModel.DataSources.Add(new Syncfusion.Reports.EJ.ReportDataSource { Name = "dsFetalDeaths", Value = ds.Tables["FetalDeaths"] });
var caseYear = new Syncfusion.Reports.EJ.ReportParameter() { Name = "CaseYear", Prompt = "Case Year", Labels = new List<string> { "CaseYear" }, Values = new List<string> { "2014" }, Nullable = false };
var countyId = new Syncfusion.Reports.EJ.ReportParameter() { Name = "CountyId", Prompt = "County ID", Labels = new List<string> { "CountyId" }, Values = new List<string> { "53" }, Nullable = false };
List<Syncfusion.Reports.EJ.ReportParameter> list = new List<Syncfusion.Reports.EJ.ReportParameter>();
list.Add(caseYear);
list.Add(countyId);
reportOptions.ReportModel.Parameters = list;
}
}
}
Thank you for your help
-Sam
protected void Page_Load(object sender, EventArgs e)
{
viewer.Parameters = new List<ReportParameter>();
viewer.Parameters.Add(new ReportParameter()
{
Name = "InvoiceID",
Labels = new List<string>() { "InvoiceID" },
Values = new List<string>() { "10250" }
});
} |