How to get refresh button to grab new data from database

13 posts, 0 answers
  1. John Hughes
    John Hughes avatar
    15 posts
    Member since:
    Mar 2010

    Posted 10 Jan 2011 Link to this post

    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
  2. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 13 Jan 2011 Link to this post

    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.
  3. DevCraft banner
  4. Jeff Reinhardt
    Jeff Reinhardt avatar
    55 posts
    Member since:
    Oct 2009

    Posted 13 Jan 2011 Link to this post

    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.
  5. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 19 Jan 2011 Link to this post

    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.
  6. Jeff Reinhardt
    Jeff Reinhardt avatar
    55 posts
    Member since:
    Oct 2009

    Posted 19 Jan 2011 Link to this post

    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.
  7. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 24 Jan 2011 Link to this post

    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.
  8. Robert Kanasz
    Robert Kanasz avatar
    1 posts
    Member since:
    Oct 2009

    Posted 28 Feb 2011 Link to this post

    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. 
  9. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 01 Mar 2011 Link to this post

    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!
  10. Adit
    Adit avatar
    14 posts
    Member since:
    Mar 2015

    Posted 17 May 2015 Link to this post

    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.
  11. Stef
    Admin
    Stef avatar
    3036 posts

    Posted 19 May 2015 Link to this post

    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
  12. Saumyadip
    Saumyadip avatar
    4 posts
    Member since:
    Apr 2014

    Posted 07 Aug 2015 in reply to Stef Link to this post

    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>
    }
  13. Stef
    Admin
    Stef avatar
    3036 posts

    Posted 12 Aug 2015 Link to this post

    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
  14. Saumyadip
    Saumyadip avatar
    4 posts
    Member since:
    Apr 2014

    Posted 12 Aug 2015 in reply to Stef Link to this post

    @Stef: Thanks for your update.
Back to Top
DevCraft banner