This is a migrated thread and some comments may be shown as answers.

Chart report ignores new data source

7 Answers 82 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Craig
Top achievements
Rank 1
Craig asked on 25 Jul 2016, 02:21 PM

I have a report that is a bar chart, which I created within VS 2013. I added a data source to the report in the report designer so that I could preview the report. Now I would like to use the report in an asp.net page. I need to be able to retrieve a data set from a web service and assign that to the report as a data source. When I run the report, it ignores the data source I'm trying to assign and always displays the results from the data I tested with.

I have tried setting the data source of the report directly. That doesn't work. I have tried using an objectdatasource. That doesn't work. How do I get the report to dynamically display?

Here is a sample of the code I'm using:

 

     Dim oReportSource As New Telerik.Reporting.InstanceReportSource
     Dim oReport As New ChartReport     
        Dim objectDataSource As New Telerik.Reporting.ObjectDataSource()
    
        Dim ds As New DataSet
        Dim eHCD As New UploadDownload.eHCDReportBroker.eHCDReportBroker

        ClearCache()
        ' ds = eHCD.GetEHCDFilesByPMID(mySession.pmsId)

        'oReport.ReportParameters("pld_file_id").Value = 3784120

        'oReport.DataSource = ds.Tables(0).Select("xmt_typ=" & ddlFileType.SelectedValue.ToString)
        ds = eHCD.GetEHCDCountsByPLDID(pld_file_id, IIf(ddlFileType.SelectedValue = 3, "T", "P"))
        ds.DataSetName = "SqlDataSource1"
        objectDataSource.DataSource = ds

        'oReport.DataSource = objectDataSource
        oReport.DataSource = ds


        ReportViewer1.Visible = True
        oReportSource.ReportDocument = oReport
        ReportViewer1.ReportSource = oReportSource
        Me.ReportViewer1.DataBind()
        ReportViewer1.RefreshData()
        ReportViewer1.RefreshReport()

 

 

7 Answers, 1 is accepted

Sort by
0
Craig
Top achievements
Rank 1
answered on 25 Jul 2016, 02:26 PM

Please ignore the code attached to the above message. It got posted before I was finished removing extraneous commands, and it seems this forum has no way to edit posts. Please refer to this code instead.

  Dim oReportSource As New Telerik.Reporting.InstanceReportSource
     Dim oReport As New ChartReport  ' this is the report I created   
        Dim objectDataSource As New Telerik.Reporting.ObjectDataSource()
    
        Dim ds As New DataSet
 
        ds = GetData()
        objectDataSource.DataSource = ds

        oReport.DataSource = objectDataSource


        oReportSource.ReportDocument = oReport
        ReportViewer1.ReportSource = oReportSource
        ReportViewer1.RefreshReport()

 

0
Stef
Telerik team
answered on 26 Jul 2016, 11:48 AM
Hi Craig,

Please check Do I need to use a Data Source component?
Also note that the Graph item is a separate data item with its own DataSource property. You need to get the data item and modify its DataSource instead of the report's one e.g.:
Dim oReportSource As New Telerik.Reporting.InstanceReportSource
Dim oReport As New ChartReport  ' this is the report I created  
Dim objectDataSource As New Telerik.Reporting.ObjectDataSource()
 
 Dim ds As New DataSet
 ds = GetData()
 
Dim graph = DirectCast(oReport.Items.Find("GraphNameCaseSensitiveHere",True)(0), Telerik.Reporting.Graph)
graph.DataSource = ds
 
 oReportSource.ReportDocument = oReport
 ReportViewer1.ReportSource = oReportSource
 ReportViewer1.RefreshReport()


I hope this information is helpful.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Craig
Top achievements
Rank 1
answered on 26 Jul 2016, 09:09 PM

Okay, I didn't realized the graph object had its own data source. With your code I'm now much closer, but there is still one problem. The graph doesn't refresh unless I click the refresh button on the reportviewer control. Calling ReportViewer1.RefreshReport() from the code behind doesn't seem to do anything.

Does the graph object have a separate refresh method as well?

0
Stef
Telerik team
answered on 27 Jul 2016, 12:57 PM
Hello  Craig,

It is not clear which viewer is in use and what changes should be applied in the report.

In general, you are getting and modifying a report in code. Then the modified report instance is passed to the viewer via ReportSource object. If changes are made to that report instance, you will have to reset the viewer's ReportSource in code.

If you are applying parameters' values, then you can use the viewer's Preview button or in code you can set the values through the viewer's ReportSource.Parameters collection. The viewer's ReportSource.Parameters collection is mapped by key (name) to the report's ReportParameters collection, and then you can call the viewer's RefreshReport method.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Craig
Top achievements
Rank 1
answered on 01 Aug 2016, 04:54 PM

Not sure what you mean by it not being clear which viewer is in use. It's the Telerik report viewer. Here is the registration from the .aspx page:

<%@ Register Assembly="Telerik.ReportViewer.WebForms, Version=10.1.16.615, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" Namespace="Telerik.ReportViewer.WebForms" TagPrefix="telerik" %>

and the element:

             <telerik:ReportViewer ID="ReportViewer1" runat="server" Width="600" Height="400" ParametersAreaVisible="False" ShowNavigationGroup="False" ShowHistoryButtons="False" ShowParametersButton="False"></telerik:ReportViewer>
                 <script type="text/javascript">
                     ReportViewer.prototype.OnReportLoadedOriginal = ReportViewer.prototype.OnReportLoaded;
   
                     ReportViewer.prototype.OnReportLoaded = function () {
                         this.OnReportLoadedOriginal();

                         var iframeID = this.clientID + "ReportFrame";

                         var iframe = document.getElementById(iframeID);

                         var wnd = iframe.contentWindow;

                         wnd.NavigateToUrl = function (url) {
                             window.radopen(url, "", 1025, 800);
                         };
                     }
                 </script>

 

The problem is, reportviewer1.RefreshReport does nothing. I have to manually click the refresh button on the viewer to refresh the report, and display the data from the dataset I just used:

     Dim graph = DirectCast(oReport.Items.Find("Graph1", True)(0), Telerik.Reporting.Graph)
        graph.DataSource = ds

        oReportSource.ReportDocument = oReport     ' this is the report with the graph on it
        ReportViewer1.ReportSource = oReportSource ' I set the report viewer's report source
        ReportViewer1.RefreshReport()   ' Does nothing

0
Nasko
Telerik team
answered on 04 Aug 2016, 11:50 AM
Hello Craig,

The provided code works correctly on our end. Please find attached a sample project demonstrating how to update the report's data source from the calling application code.

Regards,
Nasko
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Craig
Top achievements
Rank 1
answered on 17 Aug 2016, 01:50 PM

I finally figured out the problem, so I'm posting the solution here in case anybody else runs into this.

The procedure that loaded the report was being called by a radgrid column that was expanded by a user click. In order to get the chart to refresh, I needed to add the report viewer control as an ajax updated control in the RadAjaxManager that contained the grid, like so:

 

  <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" ClientEvents-OnRequestStart="mngRequestStarted">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                        <telerik:AjaxUpdatedControl ControlID="ReportViewer1"></telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
             </AjaxSettings>
        </telerik:RadAjaxManager>

 

Now the report refreshes when a row is expanded.

Tags
General Discussions
Asked by
Craig
Top achievements
Rank 1
Answers by
Craig
Top achievements
Rank 1
Stef
Telerik team
Nasko
Telerik team
Share this question
or