Refresh a Silverlight Report

12 posts, 2 answers
  1. Vuyiswa Maseko
    Vuyiswa Maseko avatar
    187 posts
    Member since:
    Jan 2010

    Posted 29 Mar 2011 Link to this post

    Good Evenign

    i am not using MVVM parttern, i looked for examples here on our site and could not find just a simple way to refresh a Reportviewer in Silverlight. The Scenirio is simple. i have a listbox outside the Report, and when the SelectedChanged even is fire, i want to refresh the report, So i tried to call the Asnyc of the "reportViewer1_RenderBegin" Event , but nothing is happenig. my renderbegin is initializing the report parameters. So i want to refresh a report.

    THanks
  2. Answer
    Steve
    Admin
    Steve avatar
    10941 posts

    Posted 30 Mar 2011 Link to this post

    Hi Vuyiswa Maseko,

    As of Q1 2011 release of Telerik Reporting the ReportViewerModel cannot be taken from the DataContext of the viewer. This is done on purpose in order to allow binding to an inherited DataContext from the viewer's properties. The new way to get the model is from the viewer's first child. Here is a sample snippet that illustrates this approach:
    Copy Code
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }
     
        void button1_Click(object sender, RoutedEventArgs e)
        {
            this.ReportViewer1.RefreshReport();
        }
    }
     
    static class ReportViewerExtensions
    {
        public static void RefreshReport(this ReportViewer reportViewer)
        {
            var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(reportViewer, 0);
            var viewerModel = (ReportViewerModel)layoutRoot.DataContext;
            var refreshCommand = viewerModel.RefreshReportCommand;
            if (refreshCommand.CanExecute(null))
            {
                refreshCommand.Execute(null);
            }
        }
    }

    Hope it helps.

    Regards,
    Steve
    the Telerik team
  3. DevCraft banner
  4. Vuyiswa Maseko
    Vuyiswa Maseko avatar
    187 posts
    Member since:
    Jan 2010

    Posted 30 Mar 2011 Link to this post

    You are a star this works perfectly.

    Thank again for your time, i will have to bother you with a non reporting quetion. i have posted it here

    http://www.telerik.com/community/forums/silverlight/gridview/single-select-on-a-gridview.aspx

    Thanks for your help. 


  5. VH
    VH avatar
    27 posts
    Member since:
    Mar 2010

    Posted 31 Mar 2011 Link to this post

    Hi,

    I want the report to be able to refresh automatically every time it is shown.
    Before I upgraded to Q1 2011, I used ((ReportViewerModel)report.DataContext).RefreshReportCommand.Execute(null); to refresh it.
    But with Q1 2011, I have tried what you suggested, but my reportviewer doesn't have any children, so when I try to call
    var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(reportViewer, 0); it gets error.
    In this case what should I do?

    Thank you for your help.
  6. PCF
    PCF avatar
    5 posts
    Member since:
    Mar 2011

    Posted 11 May 2011 Link to this post

    Hello there,
    I'm having the same exact problem. It was working great using the old Q3 2010 routine, and then I went and upgraded the reports using the upgrade wizard and now I'm having the same problem because my ReportViewer doesn't have a child and it blows up trying to GetChild().

    Help!
  7. Answer
    Steve
    Admin
    Steve avatar
    10941 posts

    Posted 16 May 2011 Link to this post

    Hello PCF,

    The only reason for this problem would be if the report viewer template has not yet been created e.g. you're invoking the extension method in the window/user control constructor. To make sure the template is available use OnApplyTemplate e.g.:

    public partial class MainPage : UserControl
       {
           public MainPage()
           {
               InitializeComponent();
           }
     
           public override void OnApplyTemplate()
           {
               base.OnApplyTemplate();
               this.ReportViewer1.RefreshReport();
           }
       }
     
       static class ReportViewerExtensions
       {
           public static void RefreshReport(this ReportViewer reportViewer)
           {
               var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(reportViewer, 0);
               var viewerModel = (ReportViewerModel)layoutRoot.DataContext;
               var refreshCommand = viewerModel.RefreshReportCommand;
               if (refreshCommand.CanExecute(null))
               {
                   refreshCommand.Execute(null);
               }
           }
       }


    Regards,
    Steve
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  8. Vuyiswa Maseko
    Vuyiswa Maseko avatar
    187 posts
    Member since:
    Jan 2010

    Posted 17 May 2011 Link to this post

    Good Day ,

    Thank you for your reply.


    private void reportViewer1_RenderBegin(object sender, Telerik.ReportViewer.Silverlight.RenderBeginEventArgs args)
    {
        KidsModelExtended selectedkid = lstkids.SelectedItem as KidsModelExtended;
     
        if (selectedkid != null)
        {
            int Kidid = selectedkid.iKidid;
            args.ParameterValues["KIDID"] = Kidid;
        }
     
         
    }
    This has worked for me. I have another question that i have asked in the other forum , maybe you can kindly answer me

    http://www.telerik.com/community/forums/silverlight/htmlplaceholder/payment-gateway-in-silverlight.aspx

    Thanks


  9. Chavdar
    Admin
    Chavdar avatar
    898 posts

    Posted 20 May 2011 Link to this post

    Hi PCF,

    Your other thread has been already answered. We hope you will find the provided links useful.

    Greetings,
    Chavdar
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  10. Wayne
    Wayne avatar
    17 posts
    Member since:
    Jan 2011

    Posted 12 Apr 2012 Link to this post

    Hi Steve,

    I have the same problem as in the last couple of posts. I have added the public override void OnApplyTemplate() function but this does not now execute. The Report I have in a Tab control, when I click on the tab I set the SelectedTabIndex. The report then renders once. I need it to render each time I change tabs. In one tab I set the parameters in the other I display the report viewer.

     

    Thanks and kind regards

    Wayne

  11. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 12 Apr 2012 Link to this post

    Hello Wayne,

    Do you have the problem if the viewer is outside of the RadTab? The RadTabControl adds report viewer every time the tab content is displayed and removes it from the visual tree every time the tab content is hidden(another tab content is displayed). So the current behavior of the report viewer is appropriate and by design.

    If you need to keep each RadTabItem's content you can set the IsContentPreserved property of RadTabControl to True.

    All the best,
    Steve
    the Telerik team
    NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.
  12. Wayne
    Wayne avatar
    17 posts
    Member since:
    Jan 2011

    Posted 18 Apr 2012 Link to this post

    Thanks, its working fine now.
    kind regards

    Wayen
  13. Vitrum
    Vitrum avatar
    3 posts
    Member since:
    Jun 2009

    Posted 08 Nov 2013 Link to this post

    ReportViewer1.Report=""
    ReportViewer1.Report="ReportName, ReportLibrary"

Back to Top
DevCraft banner