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.
Unfortunately, activation email could not send to your email. Please try again.

Datasource as parameter

Thread ID:

Created:

Updated:

Platform:

Replies:

126402 Oct 13,2016 03:01 PM Oct 25,2016 11:54 PM ASP.NET MVC 9
loading
Tags: ReportViewer
Felipe Alves
Asked On October 13, 2016 03:01 PM

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!

Yuvaraj Devarajan [Syncfusion]
Replied On October 14, 2016 05:26 AM

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.   


Felipe Alves
Replied On October 20, 2016 12:39 PM

Hi Yuvaraj,

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

How can i do??

Thanks

Yuvaraj Devarajan [Syncfusion]
Replied On October 21, 2016 03:13 AM

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. 


Felipe Alves
Replied On October 21, 2016 06:14 AM

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!

Yuvaraj Devarajan [Syncfusion]
Replied On October 24, 2016 07:11 AM

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.  


Felipe Alves
Replied On October 24, 2016 12:49 PM

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!

Yuvaraj Devarajan [Syncfusion]
Replied On October 25, 2016 06:18 AM

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. 


Felipe Alves
Replied On October 25, 2016 08:44 AM

Works!

Thanks Yuvaraj!!

Yuvaraj Devarajan [Syncfusion]
Replied On October 25, 2016 11:54 PM

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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;