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
Starting in 2019, the Reporting control is no longer included in Essential Studio. If you're experiencing issues with the Syncfusion Reporting Platform, Report Viewer, Report Designer, or Report Writer, we recommend migrating to Bold Reports, our dedicated reporting platform.

Bold Reports offers a comprehensive suite of tools and features for all your reporting needs, and we will help you make a smooth transition from the discontinued control. Our support team at https://support.boldreports.com/ is here to assist you with any questions or difficulties you may encounter during the migration process.

We thank you for choosing Syncfusion and appreciate your understanding.

Datasource as parameter

Hi, 

I'm trying send datasource name as parameter something like:

@(Html.EJ().ReportViewer("reportviewer").ProcessingMode(Syncfusion.JavaScript.ReportViewerEnums.ProcessingMode.Remote).Locale("pt-BR")
            .ReportServiceUrl("http://localhost//api/SSRSReport")
            .ReportServerUrl("http://localhostReportServer_SQLBI/")
            .DataSources(ViewBag.datasource)
            .ReportPath("/RELATORIOS_AMEND/" + ViewBag.report))

my ViewBag.datasource have string like "datasource"

but it's wrong, get error 

An exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in System.Core.dll but was not handled in user code

call ambiguous
'Syncfusion.JavaScript.ReportViewerPropertiesBuilder.DataSources(System.Action<Syncfusion.JavaScript.ReportDataSourceBuilder>)' e 'Syncfusion.JavaScript.ReportViewerPropertiesBuilder.DataSources(System.Collections.Generic.List<Syncfusion.JavaScript.Models.ReportViewer.ReportDataSource>)'



Thanks!

9 Replies

YD Yuvaraj Devarajan Syncfusion Team October 14, 2016 09:26 AM UTC

Hi Felipe, 
 
Thanks for contacting Syncfusion support. 
 
On further analysis of the shared code example, the mentioned issue might have occurred if the DataSource value is not passed properly in ReportViewer control. If we have to bind the data source value to ReportViewer for reports at runtime, then we have to specify both dataset name and dataset value in DataSource property. Also If we have to pass the local DataSource values to Report file, then we have to specify processing mode as local. So specify the processing mode as Local and specify the dataset name and dataset value in DataSource property of your application as shown in the below shared code example.   

<body style="overflow: hidden; position: static; margin: 0px; padding: 0px; width: 100%; height: 100%"> 
    <div style="width:100%; height:100%; position:absolute;"> 
        @(Html.EJ().ReportViewer("reportsample") 
        .ProcessingMode(Syncfusion.JavaScript.ReportViewerEnums.ProcessingMode.Local) 
                .ReportServiceUrl(VirtualPathUtility.ToAbsolute("~/api/ReportApi")) 
                .ReportPath("~/App_Data/GroupingAggregate.rdlc") 
                .DataSources(ds => ds.Name("Sales").Value(ViewData["DataSource"]).Add()) 
        ) 
    </div> 
    @(Html.EJ().ScriptManager()) 
 
</body> 

We have prepared the sample and it can be downloaded from, 

Please refer the below UG documentation link for more detail, 

If the issue still persists, then revert the shared sample with issue reproducible step to validate the mentioned issue at our end.   
  
Regards,   
Yuvaraj D.   



FA Felipe Alves October 20, 2016 04:39 PM UTC

Hi Yuvaraj,

I just want send string parameter into json object, like customObject

How can i do??

Thanks


YD Yuvaraj Devarajan Syncfusion Team October 21, 2016 07:13 AM UTC

Hi Felipe, 
 
We can set/pass the DataSource name and DataSource value in controller and pass the ViewData to DataSource property in ReportViewer control render viewer page as shown in the below code example. 
 
Controller: 
public ActionResult RDLCReport() 
        { 
            List<Syncfusion.JavaScript.Models.ReportViewer.ReportDataSource> datasources = new List<Syncfusion.JavaScript.Models.ReportViewer.ReportDataSource>(); 
 
            Syncfusion.JavaScript.Models.ReportViewer.ReportDataSource reportDatasource = new Syncfusion.JavaScript.Models.ReportViewer.ReportDataSource(); 
            reportDatasource.Name = "Sales"; 
            reportDatasource.Value = SalesDetails.GetData(); 
            datasources.Add(reportDatasource); 
            ViewData["DataSource"] = datasources; 
            return View(); 
        } 

View page: 
<body style="overflow: hidden; position: static; margin: 0px; padding: 0px; width: 100%; height: 100%"> 
    <div style="width:100%; height:100%; position:absolute;"> 
        @(Html.EJ().ReportViewer("reportsample") 
        .ProcessingMode(Syncfusion.JavaScript.ReportViewerEnums.ProcessingMode.Local) 
                .ReportServiceUrl(VirtualPathUtility.ToAbsolute("~/api/ReportApi")) 
                .ReportPath("~/App_Data/GroupingAggregate.rdlc") 
                .DataSources(ViewData["DataSource"] as List<Syncfusion.JavaScript.Models.ReportViewer.ReportDataSource>) 
        ) 
    </div> 
    @(Html.EJ().ScriptManager()) 
 
</body> 

We have prepared the sample and it can be downloaded from below location, 
  
If we have miss understood your requirement, then share more information about your scenario to validate the issue.  
 
Regards, 
Yuvaraj D. 



FA Felipe Alves October 21, 2016 10:14 AM UTC

Hi,

I have 25 reports for send to generic method

I just want send one string , it's string from my catalog to dataSourceCredentials and for know if report need parameters for load or not

Can we do that?


Thanks!


YD Yuvaraj Devarajan Syncfusion Team October 24, 2016 11:11 AM UTC

Hi Felipe, 
 
We can dynamically pass/load the list of report in ReportViewer viewer page and based on the report name we can set/add the datasource value and parameter value for the report in WebAPI controller as shown in the below code example,   
  
Index.cshtml 
    <script>       
        function onChange(args) { 
            var url = document.URL; 
                                  
              $("#container").ejReportViewer( 
              { 
                  reportServiceUrl: url + 'api/ReportApi', 
                  processingMode: ej.ReportViewer.ProcessingMode.Remote, 
                  reportPath: '~/App_Data/' + args.selectedText 
              });           
        } 
    </script> 

WebAPI: 
       public void OnReportLoaded(ReportViewerOptions reportOption) 
        { 
            reportOption.ReportModel.DataSources.Clear(); 
            var reportName = reportOption.ReportModel.ReportPath; 
            if (reportName.Contains("Dependent.rdl")) 
            { 
                List<ReportParameter> parameters = new List<ReportParameter>(); 
                parameters.Add(new ReportParameter() { Name = "ReportParameter1", Labels = new List<string>() { "Bikes" }, Values = new List<string>() { "1" } }); 
                reportOption.ReportModel.Parameters = parameters; 
            } 
            else if (reportName.Contains("GroupingAggregate.rdlc")) 
            { 
                reportOption.ReportModel.ProcessingMode = ProcessingMode.Local; 
                reportOption.ReportModel.DataSources.Add(new ReportDataSource { Name = "Sales", Value = SalesDetails.GetData() }); 
            } 
        } 

We have prepared the sample and it can be downloaded from the below location,  
   
If we have misunderstood your requirement, then share more information about your scenario to validate and prepare the sample.     
  
Regards,  
Yuvaraj D.  



FA Felipe Alves October 24, 2016 04:49 PM UTC

Hi,

i guess isn't what i need yet, this is my code:

    public void OnInitReportOptions(ReportViewerOptions reportOption)
        {
            string reportserverUrl = "http://localhost/ReportServer_SQLBI/";

            if (reportOption.ReportModel.ReportPath.Contains("InvoiceTemplate"))
            {
                reportOption.ReportModel.ReportServerUrl = reportserverUrl;
                reportOption.ReportModel.ReportServerCredential = new System.Net.NetworkCredential("ssrs", "RDLReport1");
                reportOption.ReportModel.DataSourceCredentials.Add(new DataSourceCredentials("NorthWindIO", "ssrs1", "RDLReport1"));
            }
            else if (reportOption.ReportModel.ReportPath.Contains("Territory Sales"))
            {
                reportOption.ReportModel.ReportServerUrl = reportserverUrl;
                reportOption.ReportModel.ReportServerCredential = new System.Net.NetworkCredential("ssrs", "RDLReport1");
                reportOption.ReportModel.DataSourceCredentials.Add(new DataSourceCredentials("AdventureWorks", "ssrs1", "RDLReport1"));
            }


I have more then 50 reports i cant write so much if else for know which DatasourceCredentials have to load, i want pass this dynamically, there is anyway to do this??


Thanks!


YD Yuvaraj Devarajan Syncfusion Team October 25, 2016 10:18 AM UTC

Hi Felipe, 
 
We can retrieve the datasource name from the report by “ReportHelper.GetDataSources()” in OnReportLoaded method and using the datasource name we can dynamically pass the Username and password for the datasource credential in WebAPI OnReportLoaded method as shown in the below code example,   

public void OnReportLoaded(ReportViewerOptions reportOption) 
        { 
            var datasets = ReportHelper.GetDataSources(); 
            foreach (var item in datasets) 
            {                
                reportOption.ReportModel.DataSourceCredentials.Add(new DataSourceCredentials(item.DataSourceName, "ssrs1", "RDLReport1")); 
            } 
        }        

We have prepared the sample based on this and it can be downloaded from, 

Regards, 
Yuvaraj D. 



FA Felipe Alves October 25, 2016 12:44 PM UTC

Works!

Thanks Yuvaraj!!


YD Yuvaraj Devarajan Syncfusion Team October 26, 2016 03:54 AM UTC

Hi Felipe, 
 
Thanks for the update. We are happy to hear that your issue is resolved. 
 
Regards, 
Yuvaraj D. 


Loader.
Live Chat Icon For mobile
Up arrow icon