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

How to get refresh button to grab new data from database

12 Answers 901 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
John Hughes
Top achievements
Rank 1
John Hughes asked on 10 Jan 2011, 11:38 PM
It seems if I click on the refresh button in the Report Viewer toolbar it will re-render the current data on the screen.  How do I connect to that button so that it grabs the latest data from the database and renders it?   Right now my QA person is hand editing the DB while testing our tool and expected the refresh button to show the changes from the DB.  Is there a method I need to implement to handle this in my C# code?

Thanks,

John

12 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 13 Jan 2011, 06:56 PM
Hi John,

Actually your expectation of how this should work is exactly how the Telerik Reporting works i.e. clicking the refresh button processed the report from scratch.
Since we're not aware with your scenario, we have a suspicion that you might be binding Using the NeedDataSource event and assign the datasource to the definition item instead of its processing counterpart. Check if this is not the case and if the problems stands, provide more information or runnable report that exhibits the problem.

Greetings,
Steve
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Jeff Reinhardt
Top achievements
Rank 1
answered on 13 Jan 2011, 08:02 PM
Actually I have the same issue. The refresh button does not show updated data on refresh, only closing the report viewer and running again from scratch works.

Datasource set:

report.DataSource = objectDS;

Report Viewer Call:

ReportViewer1.Report = report;
ReportViewer1.RefreshReport();

When the report comes up I can change data in the database and hit refresh and still see the old data.
0
Steve
Telerik team
answered on 19 Jan 2011, 01:05 PM
Hi guys,

I made the simplest test possible to verify the correct behavior. A Report is bound to a DataTable and shown in the web report viewer. Here is the datasource:

public class MySampleData : DataTable
   {
       public MySampleData()
       {
           this.Columns.Add("col1", typeof(int));
           this.Columns.Add("col2", typeof(string));
 
           this.Rows.Add(1, "test1");
           this.Rows.Add(2, "test2");
       }
   }

and in the web page I add a new row to the DataTable from external UI e.g. button click:

protected void Button1_Click(object sender, EventArgs e)
   {
       Telerik.Reporting.Report report = (Telerik.Reporting.Report)this.ReportViewer1.Report;
       DataTable dt = (DataTable)report.DataSource;
       dt.Rows.Add(3, "test3");
   }

Then we click the refresh button and the report shows the new data as expected. You can also invoke the RefreshReport() method in the button click. I've attached the report and .aspx page for your convenience.

Best wishes,
Steve
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Jeff Reinhardt
Top achievements
Rank 1
answered on 19 Jan 2011, 02:51 PM
I am sorry but I do not find this to be a similar test.  I am not using a datatable, and I am not doing anything datasource wise inside the report itself.

Here is a trimmed down code view of my ReportViewer.aspx.cs

Telerik.Reporting.Report report = null;
Telerik.Reporting.SubReport subReport = null;
Telerik.Reporting.ObjectDataSource objectDS = new Telerik.Reporting.ObjectDataSource();
 
DataSet DS = new DataSet();
DataSet subDS = new DataSet();
 
// these lines call a couple class methods to fill the datasets
Order.GetAsDatasetByID(OrderID, ref DS, ref errorMsg);
OrderDetail.GetByID(OrderID, ref subDS, ref errorMsg);
report = new Common.Order();
subReportName = "srItemDetails";
objectDS.DataSource = DS;
report.DataSource = objectDS;
subReport = (Telerik.Reporting.SubReport)report.Items.Find(subReportName, true)[0];
subReport.ReportSource.DataSource = subDS;
 
ReportViewer1.Report = report;
ReportViewer1.RefreshReport();

As you can see I am setting the Datasource of both the report and subreport from outside using DataSets that were retrieved from our class calls.

When I refresh the report having changed something in the SQL database that those methods retrieve the data from using Stored Procedure calls, the data is NOT updated in the report.  For example, this is an Order Acknowledgement report, I ran the report, noticed a price error on an item, fixed it in the database and refreshed the report.  The pricing did not change on the report.  If I close the report and re-run it, it then shows the updated price.

The Report Viewer itself is simply:  <telerik:ReportViewer ID="ReportViewer1" runat="server" style="border:1px solid #ccc;" width="99%" height="101%"/>

The reports contain no code at all in the code behinds, they are simply layouts for the datasets that are passed to them.
0
Steve
Telerik team
answered on 24 Jan 2011, 07:35 PM
Hi John,

Please use the standard asp:GridView control using the same datasource and see if it behaves the way you expect. If not, clearly the problem is out of our domain. If it works correctly with the GridView, please provide us with a sample runnable project which exhibits the runnable grid and failing report viewer and we would advise you accordingly.

Greetings,
Steve
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Robert Kanasz
Top achievements
Rank 1
answered on 28 Feb 2011, 07:03 PM
Hi,
I have similar problem. Now I'm investigating functionality of Telerik Reporting and I try to display DataTable in ReportViewer. I have found article about that:
http://www.telerik.com/help/reporting/object-data-source-how-to-bind-to-data-table.html
I copied source code of this example and modify it (I have modified connection string). Problem is, that ReportViewer still shows only blank page with no data. I have absolutely no idea, where is tho problem. GetData method returns row from Production.Product table (more than 500). I didn't receive any error.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Collections;
using System.Windows.Forms;
 
namespace TelerikReportingForm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            Telerik.Reporting.ObjectDataSource objectDataSource = new Telerik.Reporting.ObjectDataSource();
            objectDataSource.DataSource = GetData(); // GetData returns a DataTable
            objectDataSource.CalculatedFields.Add(new Telerik.Reporting.CalculatedField("FullName", typeof(string), "=Fields.Name + ' ' + Fields.ProductNumber")); // Adding a sample calculated field.
            Telerik.Reporting.Report report = new Telerik.Reporting.Report();
            report.DataSource = objectDataSource;
            reportViewer1.Report = report;
            reportViewer1.RefreshReport();
        }
 
        private DataTable GetData()
        {
            const string connectionString =
           "Data Source=ANANAS\\ANANAS2009;Initial Catalog=AdventureWorks;Integrated Security=True";
            string selectCommandText = "SELECT * FROM Production.Product;";
            SqlDataAdapter dataAdapter = new SqlDataAdapter(selectCommandText, connectionString);
            DataTable dataTable = new DataTable();
            dataAdapter.Fill(dataTable);
            return dataTable;
        }
    }
}

Can you tell me, what i'm doing wrong? I have fount on previous thread AutoGenerateColums solution. Is this necessary to use this approach? I though that ReportViewer could automatically generate colums. (maybe I'm wrong).
btw. now I'm using TRIAL version of Telerik Reporting.
When I use static reports I have no problems. 
0
Steve
Telerik team
answered on 01 Mar 2011, 08:40 AM
Hi Robert,

You've figured it out correctly - the report cannot autogenerate columns and you have to manually create its layout either entirely by code or by creating a Telerik Reporting in Visual Studio, create the layout with the help of the Report Designer and then instantiate your report instead of the base class.

Kind regards,
Steve
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Adit
Top achievements
Rank 1
answered on 17 May 2015, 12:18 PM
We can see that on external button click we can access Report Viewer and its controls. Our questions is how can we get this access on MVC Reporting. We are using Q1 2015 fro reporting.
0
Stef
Telerik team
answered on 19 May 2015, 01:17 PM
Hi Adit,

I am uncertain about the required functionality.
  • If you refer to creating/modifying reports before displaying them in the HTML5 Report Viewer, you can do so via custom report resolver used by the Reporting REST service.

    How the viewer(client)-service pair works:

    Basically, the client (viewer) sends string description of the requested report (the viewer's reportSource.report value) to the service, and depending on the report resolvers in the service this string description will be resolved to a report source object.
    By default we provide ReportFileResolver and ReportTypeResolver, which allows you to work with reports saved as TRDX files or built in a DLL.
    You can also create your own report resolvers as in the example in the How To: Implement a Custom Report Resolver article (useful if you need to customize the report before displaying it via InstanceReportSource).


  • If you refer to refreshing the HTML5 Viewer, please check the discussion in Web Api Caching and resolving issues (my last two posts), and test the provided suggestions - upgrade to Telerik Reporting v9.0.15.422 and/or adding a DateTime parameter in the report.



If you have further questions, please elaborate on the scenario and the required changes in the report or/and the viewer.

Regards,
Stef
Telerik
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
Saumyadip
Top achievements
Rank 2
answered on 07 Aug 2015, 01:58 PM
How to get search button to grab new data from database in Telerik Report using code .


HTML Section 
@using Telerik.Reporting.Examples.CSharp.ZipCodeReport;


@{
    ViewBag.Title = "Zip Code Report";
    Layout = "~/Views/Shared/_LayoutAllReport.cshtml";
}
@section styles
{
    <link href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet" />
    <link href="http://cdn.kendostatic.com/2013.2.918/styles/kendo.common.min.css" rel="stylesheet" />
    @*<link href="http://cdn.kendostatic.com/2013.2.918/styles/kendo.blueopal.min.css" rel="stylesheet" />*@


    <style>
        #reportViewer1 {
            position: relative;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            overflow: hidden;
            font-family: Verdana, Arial;
            height: 1150px;
        }
         #reportViewer1 .trv-parameters-area {
            display:none;
        }


    </style>
    <link href="@Url.Content("~/ReportViewer/styles/telerikReportViewer-9.0.15.324.css")" rel="stylesheet" />
}


<div style="background:#fff; border-bottom: 3px solid #396087;">
    <div class="container">
        <div class="row">
            <div class="col-md-9">
                <div class="clearfix">
                    <div class="col-md-2 form-group clearfix">
                        <label>Date From</label>
                        @(Html.Kendo().DatePicker().Name("DateFrom")
                              .Value(Utility.Common.common.ConvertUTCtoLocalTime(DateTime.UtcNow)).Format("MM/dd/yyyy")
                              .Max(DateTime.Today)
                              .Events(e =>
                              {
                                  e.Change("dateChanged");
                              })
                        )
                    </div>
                    <div class="col-md-2 form-group clearfix">
                        <label>Date To</label>
                        @(Html.Kendo().DatePicker().Name("DateTo")
                          .Value(Utility.Common.common.ConvertUTCtoLocalTime(DateTime.UtcNow)).Format("MM/dd/yyyy")
                          .Max(DateTime.Today)
                          .Events(e =>
                          {
                              e.Change("dateChanged");
                          })
                        )
                    </div>
                    <div class="col-md-2 form-group clearfix">
                        <label>&nbsp;</label>
                        @(Html.Kendo().Button()
                                .Name("btnSearch")
                                .HtmlAttributes(new { type = "button", @class = "small-button" })
                                .Content("Search"))


                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="top-btn floatR" style="margin-top:20px;">
                    <a id="iconTextButton2" href="/Patient/List" class="k-button" data-role="button" role="button" aria-disabled="false" tabindex="0">Find Patient</a>
                    <script>
                        jQuery(function () { jQuery("#iconTextButton2").kendoButton({}); });
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="container">
    <div class="row">
        @{
            var typeReportSource = new TypeReportSource() { TypeName = typeof(ZipCodeReport).AssemblyQualifiedName };
            typeReportSource.Parameters.Add("DisplayDateFrom", Utility.Common.common.ConvertUTCtoLocalTime(DateTime.UtcNow).ToString("MM/dd/yyyy"));
            typeReportSource.Parameters.Add("DisplayDateTo", Utility.Common.common.ConvertUTCtoLocalTime(DateTime.UtcNow).ToString("MM/dd/yyyy"));
        }


        @(Html.TelerikReporting().ReportViewer()
                                        // Each report viewer must have an id - it will be used by the initialization script
                                        // to find the element and initialize the report viewer.
                            .Id("reportViewer1")
                                        // The URL of the service which will serve reports.
                                        // The URL corresponds to the name of the controller class (ReportsController).
                                        // For more information on how to configure the service please check http://www.telerik.com/help/reporting/telerik-reporting-rest-conception.html.
                            .ServiceUrl(Url.Content("~/api/reports/"))
                                        // The URL for the report viewer template. The template can be edited -
                                        // new functionalities can be added and unneeded ones can be removed.
                                        // For more information please check http://www.telerik.com/help/reporting/html5-report-viewer-templates.html.
                            .TemplateUrl(Url.Content("~/ReportViewer/templates/telerikReportViewerTemplate-9.0.15.324.html"))
                                        // Strongly typed ReportSource - TypeReportSource or UriReportSource.
                                                            .ReportSource(typeReportSource)
                                        // Specifies whether the viewer is in interactive or print preview mode.
                                        // PRINT_PREVIEW - Displays the paginated report as if it is printed on paper. Interactivity is not enabled.
                                        // INTERACTIVE - Displays the report in its original width and height with no paging. Additionally interactivity is enabled.
                            .ViewMode(ViewModes.PRINT_PREVIEW)
                                        // Sets the scale mode of the viewer.
                                        // Three modes exist currently:
                                        // FIT_PAGE - The whole report will fit on the page (will zoom in or out), regardless of its width and height.
                                        // FIT_PAGE_WIDTH - The report will be zoomed in or out so that the width of the screen and the width of the report match.
                                        // SPECIFIC - Uses the scale to zoom in and out the report.
                            .ScaleMode(ScaleModes.SPECIFIC)
                                        // Zoom in and out the report using the scale
                                        // 1.0 is equal to 100%, i.e. the original size of the report
                            .Scale(1.0)
                                        // Sets whether the viewer’s client session to be persisted between the page’s refreshes(ex. postback).
                                        // The session is stored in the browser’s sessionStorage and is available for the duration of the page session.
                            .PersistSession(false)
                                        // Sets the print mode of the viewer.
                            .PrintMode(PrintMode.AutoSelect)
                                        // Defers the script initialization statement. Check the scripts section below -
                                        // each deferred script will be rendered at the place of TelerikReporting().DeferredScripts().
                            .Deferred()




        )


    </div>
</div>






Script Section




@section scripts
{
    <!--kendo.all.min.js can be used as well instead of kendo.web.min.js and kendo.mobile.min.js-->
    <script src="@Url.Content("~/ReportViewer/js/telerikReportViewer-9.0.15.324.js")"></script>
    <script src="http://cdn.kendostatic.com/2013.2.918/js/kendo.web.min.js"></script>
    <!--kendo.mobile.min.js - optional, if gestures/touch support is required-->
    <script src="http://cdn.kendostatic.com/2013.2.918/js/kendo.mobile.min.js"></script>
    @(




        // All deferred initialization statements will be rendered here
        Html.TelerikReporting().DeferredScripts()
    )


    <script type="text/javascript">


        function ReportViwerLoad()
        {
            var reportUrl = '@Url.Action("GetConvertUTCtoLocalTime", "Report")';
            reportUrl = reportUrl + '?DateFrom=' + $("#DateFrom").val() + ' ' + get12HourFormatTime(new Date()) + '&DateTo=' + $("#DateTo").val() + ' ' + get12HourFormatTime(new Date());
            $.ajax({
                type: "POST",
                url: reportUrl,
                dataType: 'json',
                success: function (data) {
                    var viewer = $("#reportViewer1").data("telerik_ReportViewer");
                    viewer.reportSource({
                        report: viewer.reportSource().report,
                        parameters: { DateFrom: data.returnVal.DateFrom, DateTo: data.returnVal.DateTo, DisplayDateFrom: $("#DateFrom").val(), DisplayDateTo: $("#DateTo").val() }
                    });





                    viewer.refreshReport();
                },
                error: function () {  }
            });
        }




        $("#btnSearch").click(function () {
            ReportViwerLoad();
        });


        function dateChanged()
        {
            ReportViwerLoad();
        }


    </script>
}
0
Stef
Telerik team
answered on 12 Aug 2015, 10:51 AM
Hello,

@Saumyadip: Thank you for this post.

For anyone concerned in Telerik Reporting Q2 2015 SP1 v9.1.15.731 there is a setting of the Reporting REST service configuration allowing you to invalidate the cached reports - HTML5 Report Viewer and Reporting REST services cache management.

The approach illustrated by Saumyadip is applicable in older versions, where the setting is not yet available.

Regards,
Stef
Telerik
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
Saumyadip
Top achievements
Rank 2
answered on 12 Aug 2015, 11:01 AM
@Stef: Thanks for your update.
Tags
General Discussions
Asked by
John Hughes
Top achievements
Rank 1
Answers by
Steve
Telerik team
Jeff Reinhardt
Top achievements
Rank 1
Robert Kanasz
Top achievements
Rank 1
Adit
Top achievements
Rank 1
Stef
Telerik team
Saumyadip
Top achievements
Rank 2
Share this question
or