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

Siverlight Change Report Does Not Render New Report

1 Answer 57 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Brian Wilkinson
Top achievements
Rank 1
Brian Wilkinson asked on 16 Jun 2012, 10:08 PM
In my little silverlight application I've just bound up the ReportViewers Report Property to the selected item of a combobox. When I change the selected report the report viewer does not render the new report apart for the first time you select a report, it always stays the same as the original report generated.
I've checked on the server to ensure the new report is being passed back to the server correctly and in RenderAndCache, the report is passed back correctly.
The combobox is populated form calling the server to get available reports.


Can anyone help with what I'm doing wrong.

Regards
             Brian Wilkinson

1 Answer, 1 is accepted

Sort by
0
Accepted
Peter
Telerik team
answered on 20 Jun 2012, 02:50 PM
Hi Brian,

Check out the following code snippet that illustrates how to accomplish your requirement. If you still experience any difficulties please open a support thread and send us a sample project that exhibits the issue to debug on our end.

public class MainPageModel : INotifyPropertyChanged
  {
      static readonly ReportInfo noReportInfo = new ReportInfo { Name = "No report." };
      static readonly ReportInfo loadingReportInfo = new ReportInfo { Name = "Loading reports..." };
 
      ReportServiceClient serviceClient;
      string reportServiceUri;
      bool hasReports;
      ReportInfo selectedReportInfo;
      IList<ReportInfo> availableReports;
 
      public event PropertyChangedEventHandler PropertyChanged;
 
      public ReportInfo SelectedReport
      {
          get { return this.selectedReportInfo; }
          set
          {
              this.selectedReportInfo = value;
              this.NotifyPropertyChanged("SelectedReport");
          }
      }
 
      public string ReportServiceUri
      {
          get { return this.reportServiceUri; }
          set
          {
              if (null != this.serviceClient)
              {
                  this.serviceClient.ListAvailableReportsCompleted -= this.OnListAvailableReportsCompleted;
                  this.serviceClient = null;
              }
 
              this.reportServiceUri = value;
              this.NotifyPropertyChanged("ReportServiceUri");
 
              if (!string.IsNullOrEmpty(this.reportServiceUri) && !DesignerProperties.IsInDesignTool)
              {
                  this.serviceClient = new ReportServiceClient(ReportViewer.EnsureAbsoluteUri(new Uri(this.reportServiceUri, UriKind.RelativeOrAbsolute)));
                  this.serviceClient.ListAvailableReportsCompleted += this.OnListAvailableReportsCompleted;
                  this.BeginLoadReports();
              }
          }
      }
 
      public bool HasReports
      {
          get { return this.hasReports; }
          set
          {
              this.hasReports = value;
              this.NotifyPropertyChanged("HasReports");
          }
      }
 
      public IList<ReportInfo> AvailableReports
      {
          get { return this.availableReports; }
          set
          {
              this.availableReports = value;
              this.NotifyPropertyChanged("AvailableReports");
          }
      }
 
      public MainPageModel()
      {
          this.HasReports = false;
      }
 
      void BeginLoadReports()
      {
          this.HasReports = false;
           
          this.AvailableReports = new [] { loadingReportInfo };
          this.SelectedReport = this.AvailableReports[0];
 
          this.serviceClient.ListAvailableReportsAsync();
      }
 
      void OnListAvailableReportsCompleted(object sender, ListAvailableReportsEventArgs e)
      {
          var reportAvailable = false;
          var reports = e.Reports;
          if (null != reports && reports.Count > 0)
          {
              this.AvailableReports = reports;
              reportAvailable = true;
          }
          else
          {
              this.AvailableReports = new[] { noReportInfo };
          }
 
          this.HasReports = reportAvailable;
          this.SelectedReport = this.AvailableReports[0];
      }
 
      void NotifyPropertyChanged(string propertyName)
      {
          if (null != this.PropertyChanged)
          {
              this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
          }
      }
  }
Regards,
Peter
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

Tags
General Discussions
Asked by
Brian Wilkinson
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or