Articles in this section
Category / Section

How to assign the data from asynchronous (async) service in Syncfusion ASP.NET ReportViewer?

2 mins read

You can assign the data from asynchronous (async) service using Syncfusion ASP.NET ReportViewer. The following steps guide you to assign the data from asynchronous (async) service from the OnReportLoaded method in the Web API controller.

1. Create a simple ReportViewer application with the help of getting started documentation.

2. Get asynchronous (async) service data in the Report API controller from the OnReportLoaded method as shown in the following code snippet.

ReportAPIController.cs

    public class ReportApiController : ApiController,IReportController
    { 
        public object PostReportAction(Dictionary<string, object> jsonResult)
        {
            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)
        {            
        }
 
        //Method will be called when reported is loaded
   public async void OnReportLoaded(ReportViewerOptions reportOption)
    {
            if (reportOption.ReportModel.ProcessingMode == ProcessingMode.Local)
            {
                reportOption.ReportModel.DataSources.Clear();
                var ReportData = await GetListAsyncData();
                reportOption.ReportModel.DataSources.Add(new ReportDataSource { Name = "StoreSales", Value = ReportData });
            }
    }
 
   private async Task<IEnumerable<StoreSales>> GetListAsyncData()
   {    
        List<StoreSales> sales = new List<StoreSales>();
        StoreSales strSal = null;
        strSal = new StoreSales()
        {
            SalesOrderID = 43659,
            TotalDue = 23153.2339,
            CustomerID = 29825,
            StateProvinceCode = "GA",
            Store = "Better Bike Shop"
        };
        sales.Add(strSal);
        strSal = new StoreSales()
        {
            SalesOrderID = 43663,
            TotalDue = 472.3108,
            CustomerID = 29565,
            StateProvinceCode = "CA",
            Store = "World Bike Discount Store"
        };
        sales.Add(strSal);
        strSal = new StoreSales()
        {
            SalesOrderID = 43673,
            TotalDue = 4216.0258,
            CustomerID = 29844,
            StateProvinceCode = "NH",
            Store = "Seventh Bike Store"
        };
        sales.Add(strSal);
        strSal = new StoreSales()
        {
            SalesOrderID = 43675,
            TotalDue = 6434.0848,
            CustomerID = 29827,
            StateProvinceCode = "MO",
            Store = "First Bike Store"
        };
        sales.Add(strSal); 
        return sales;
    }
}
 
public class StoreSales
{
    public int SalesOrderID { get; set; }
    public double TotalDue { get; set; }
    public int CustomerID { get; set; }
    public string Store { get; set; }
    public string StateProvinceCode { get; set; }
}

 

Note:

A new version of Essential Studio for ASP.NET is available. Versions prior to the release of Essential Studio 2014, Volume 2 will now be referred to as a classic versions.The new ASP.NET suite is powered by Essential Studio for JavaScript providing client-side rendering of HTML 5-JavaScript controls, offering better performance, and better support for touch interactivity. The new version includes all the features of the old version, so migration is easy.

The Classic controls can be used in existing projects; however, if you are starting a new project, we recommend using the latest version of Essential Studio for ASP.NET. Although Syncfusion will continue to support all Classic Versions, we are happy to assist you in migrating to the newest edition.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls. If you have any queries or require clarifications, please let us know in the comments section below.

You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!



Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied