We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
If you became a customer of the Syncfusion Reporting Platform or the Report Viewer, Report Designer, or Report Writer components before October 2019 and have questions related to those products, you can request support through our forum system. However, please note that this support system is only for existing customers who are still using the Syncfusion Reporting Platform or its components and not for new customers looking for reporting products from Syncfusion.

For new customers or those with general reporting questions, we recommend contacting our support team at https://support.boldreports.com/, which is a separate brand created by Syncfusion for its reporting solutions. Our team will be happy to assist you with any questions you may have.

Thank you for choosing Syncfusion for your reporting needs.

Dynamically refresh datasources based on user parameters

Hi,

I am using a trial of bold reports (RDLC & MVC 5 application). I have a requirement to refresh the report data sources based on report parameters. I am able to initially fill the datasources and the view the report but when I change the value one of the parameters, I need to refresh the query accordingly and display the result.
Thanks for your help.

YL

Attachment: Report_879b4e64.zip

5 Replies

MS Mahendran Shanmugam Syncfusion Team November 18, 2019 07:02 AM UTC

Hi Yousri, 

We cannot able to change the RDLC datasource when changing the parameter values in parameter dialog. But we can able to filter the data for RDLC report at programmatically as shown in below code when clicking the external button in example. 
<div style="height: 600px; width: 950px;"> 
        <label> 
            CustomerID: 
            <input type="text" name="CustomerID" id="customerid" > 
        </label> 
        <input type="button" value="Submit"  onclick="onClick()" > 
        <!-- Creating a div tag which will act as a container for boldReportViewer widget.--> 
        <div style="height: 600px; width: 950px; min-height: 400px;" id="viewer"></div> 
        <!-- Setting property and initializing boldReportViewer widget.--> 
        <script type="text/javascript"> 
            var parameters = [{ 
                name: 'CustomerID', 
                labels: ['29661'], 
                values: [29661], 
                nullable: false 
            }]; 
 
            $(function () { 
                $("#viewer").boldReportViewer({ 
                    reportServiceUrl: 'http://localhost:62611/api/ReportApi', 
                    reportPath: 'Region.rdlc', 
                    processingMode: ej.ReportViewer.ProcessingMode.Local, 
                    ajaxBeforeLoad: ajaxBeforeLoad, 
                    parameters: [{ 
                        name: 'CustomerID', 
                        labels: ['29661'], 
                        values: [29661], 
                        nullable: false 
                    }] 
                }); 
            }); 
 
            function ajaxBeforeLoad(event) { 
                event.data = parameters; 
            }; 
 
            function onClick(element) { 
                parameters = [{ 
                    name: 'CustomerID', 
                    labels: [document.getElementById("customerid").value], 
                    values: [document.getElementById("customerid").value], 
                    nullable: false 
                }]; 
                var reportviewer = $("#viewer").data('boldReportViewer'); 
                reportviewer.setModel({ "parameters": parameters }); 
            }; 
        </script> 
    </div> 
</body> 
</html> 
  
    [RoutePrefix("api/ReportApi")] 
    [EnableCors(origins: "*", headers: "*", methods: "*")] 
    public class ReportApiController : ApiController,IReportController  
    { 
        protected string reportPath = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/"); 
        public string DefaultParam = null; 
        //Post action for processing the rdl/rdlc report  
        [HttpPost] 
        [Route("PostReportAction")] 
        public object PostReportAction(Dictionary < string, object > jsonResult)  
        { 
            if (jsonResult.ContainsKey("customData")) 
            { 
                DefaultParam = jsonResult["customData"].ToString(); 
            } 
 
            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); 
        } 
         
        //Method will be called when initialize the report options before start processing the report         
        public void OnInitReportOptions(ReportViewerOptions reportOption) 
        { 
            reportOption.ReportModel.ReportPath = reportPath + reportOption.ReportModel.ReportPath; 
            reportOption.ReportModel.DataSources.Clear(); 
        } 
 
        //Method will be called when reported is loaded 
        public void OnReportLoaded(ReportViewerOptions reportOption)  
        { 
            var parameters = new List<ReportParameter>(); 
            if (DefaultParam != null) 
            { 
                parameters = JsonConvert.DeserializeObject<List<ReportParameter>>(DefaultParam); 
            } 
 
            if (parameters != null && parameters.Count > 0) 
            { 
                reportOption.ReportModel.DataSources.Clear(); 
                reportOption.ReportModel.DataSources.Add(new ReportDataSource { Name = "StoreSales", Value = StoreSales.GetData(Convert.ToInt32(parameters[0].Values[0])) }); 
            } 
        } 
    } 
 
Please find the below attached application for your reference. 

Regards, 
Mahendran S. 



YL Yousri Lachtar November 18, 2019 02:08 PM UTC

Thanks for your reply.
Can we do the same thing without the custom button. I mean from the oob button "VIEW REPORT" ?

YL


VS Vinoth Srinivasan Syncfusion Team November 19, 2019 01:25 PM UTC

Hi Yousri, 
 
Currently we don’t have option to filter the data when clicking the ViewReportClick for RDLC report. So, could you please set the filter for report items based on parameters as shown in below example. 
 
 
 
Regards, 
Vinoth S. 



YL Yousri Lachtar November 23, 2019 08:16 PM UTC

Thanks for your help.


VS Vinoth Srinivasan Syncfusion Team November 25, 2019 05:59 AM UTC

Hi Yousri, 

Thanks for your update. Please let us know if you require further assistance on this. 

Regards, 
Vinoth S. 


Loader.
Live Chat Icon For mobile
Up arrow icon