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

Q1 2009 can't set DataSource through code at run-time anymore??

12 Answers 291 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nate Pinchot
Top achievements
Rank 1
Nate Pinchot asked on 13 Mar 2009, 08:24 PM
Just upgraded to Q1 2009 trying to compile my web application I am getting this error message.
'Telerik.Reporting.IReportDocument' does not contain a definition for 'DataSource' and no extension method 'DataSource' accepting a first argument of type 'Telerik.Reporting.IReportDocument' could be found (are you missing a using directive or an assembly reference?)

I looked through the documentation and can't find an answer to this simple question:
How do I set the DataSource of the Report at run-time through code?
I used to use the ReportViewer1.Report.DataSource but it seems DataSource is no longer there. Please help.

Nate

12 Answers, 1 is accepted

Sort by
0
prismcarlson
Top achievements
Rank 1
answered on 13 Mar 2009, 09:21 PM
I'm having the same problem. Anyone have any clues to how it's supposed to be done now?
0
Svetoslav
Telerik team
answered on 16 Mar 2009, 01:02 PM
Hello guys,

With the new version of Telerik Reporting - Q1 2009 -  we introduced a new functionality, called Report Book, that allows you to combine two or more reports in a single document.  While developing the new feature, our primary goal was to make the reporting engine work  no matter if it should render one or more reports. This new requirement imposed the need to abstract the single Report and the aggregation of two or more reports into the new IReportDocument interface.

Starting with the 2009 Q1 version of Telerik Reporting both Windows Forms and ASP.NET Report Viewer controls operate with IReportDocument objects instead of single Report objects. Compared to the Report object the new interface exposes a limited functionality that we consider common for both Report and Report Book. This means that it is not possible to use the ReportViewer.Report property as before and this applies to both viewers.

In case you are sure that the viewer is currently showing a single report and you need to access its DataSource property you can always cast the object returned by the ReportViewer.Report property to Telerik.Reporting.Report type:

((Telerik.Reporting.Report)this.reportViewer1.Report).DataSource = ds; 

Another possible solution is to completly initialize your reports before passing in to the viewer to show them. Anyway you should always instantiate your report before passing it to the viewer so there is no need to access it back through the viewer:

MyReport myReport = new MyReport(); 
myReport.DataSource = ds; 
 
this.reportViewer1.Report = myReport; 

In case you need to set a data source for a Report from outside you can also consider using the Report.NeedDataSource event as well.

Greetings,
Svetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Yuvika
Top achievements
Rank 1
answered on 16 Mar 2009, 02:39 PM

Hi,

I am also having problem updating the report being displayed in "Report Viewer". The report viewer only shows the report that is opened the first time. I was using this code in the previous version and it was working. I upgraded yesterday and now it does not work. The reports are given the datasource in the rpt file on need_datasource event. The need datasource of the report that was opened the first time is called always. What culd be problem?????. 

 

Report1 rpt1 = new Report1(64); 
ReportViewer1.Report = rpt2;

 

Report2 rpt2 = new Report1(64);    
ReportViewer1.Report = rpt2;

Thanks and Regards
Yuvika

0
Charles Richardson
Top achievements
Rank 1
answered on 17 Mar 2009, 05:59 PM
You suggested the following:

MyReport myReport = 
new MyReport(); 
myReport.DataSource = ds; 
 
this.reportViewer1.Report = myReport; 


The same error occurs: "Datasource is not a member of MyReport."

This seems like a major change...there could be more documentation about this than there is.
0
prismcarlson
Top achievements
Rank 1
answered on 17 Mar 2009, 06:02 PM
This suggestion by Telerik in this thread solved my issue addressed in this thread.

 

 

groupObjectives myReport = new groupObjectives();    
 
myReport.DataSource = dt;  
rptViewer.Report = myReport;  
rptViewer.DataBind();  
 
 

 

 

 

 

0
Charles Richardson
Top achievements
Rank 1
answered on 17 Mar 2009, 06:20 PM
I tried that, but still got the same error...Datasource is not a property of report.
0
Steve
Telerik team
answered on 18 Mar 2009, 08:32 AM
Hi guys,

@Eric: you should not call the DataBind() method as it is not applicable to the report viewer (inherited property).
@Charles: These changes have made it in our release notes (breaking changes at the bottom) and the first reply in this thread is quote from the referenced KB article from the release notes. If you are still having problems, it would be best to prepare a sample project and attach it to a support ticket so that we can look into it, but as Eric mentioned, this should work properly. Posting your previous code that worked would also help.

Regards,
Steve
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Grégoire
Top achievements
Rank 1
answered on 01 Apr 2009, 01:31 PM
Hello,

I've got the same problem. With Q3.2008, I could see all my data, but now (with Q1.2009) the report shows only the header (no data are search anymore).
I'm using a collection (with a class as elements) as datasource. This collection is dynamic and is created with a "GetData()" function. The NeedDataSource event seems never to be called. I tried to set the datasource directely with my function "GetData()" but even if the collection has got data, nothing is visible on the report except the header.

 

 

 

Public Sub RefreshData() Implements IReporting.RefreshData  
    With DirectCast(Me.Report, Telerik.Reporting.Report)  
        .DataSource = Nothing 
        AddHandler .NeedDataSource, AddressOf Report_NeedDataSource  
    End With  
End Sub  
 
Private Sub Report_NeedDataSource(ByVal sender As Object, ByVal e As System.EventArgs)  
    TryCast(sender, Telerik.Reporting.Processing.Report).DataSource = Me.GetData()  
 
End Sub  
 
 
 

 

0
Chavdar
Telerik team
answered on 06 Apr 2009, 11:47 AM
Hello Grégoire,

Your code seems to be correct so we will need additional information in order to investigate the problem. Could you please open a support ticket and send us the report definition and the GetData function so that we can check what possibly can be wrong?

Thank you in advance.

Greetings,
Chavdar
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Adam
Top achievements
Rank 1
answered on 06 Apr 2009, 03:15 PM
I'm having the same problem as Yuvika.

I have a couple of date pickers at the top of my page and a generate button.   The generate button calls a custom function that uses the date fields to filter and returns a DataTable.  When the page loads, there is no report assigned to the ReportViewer.  Pushing the generate button works correctly the first time.  Changing the filters and pushing the button again only causes the ReportViewer to flash and show the same data.  I set a breakpoint and verified my DataTable has the correct values.

DataTable data = _dataService.GetFilteredData(startDate.SelectedDate, endDate.SelectedDate);  
 
Report r = new MyReport();  
r.DataSource = data;  
 
reportViewer.Report = r; 

I tried setting r.DataSource = null before I set my data source and doing reportViewer.DataBind(); after, but neither helped.

Update:  Found another post that mentioned disabling view state on the ReportViewer.  That fixed my issue.

<telerik:ReportViewer ID="reportViewer" runat="server" Width="100%" EnableViewState="false">  
</telerik:ReportViewer> 
 
0
Blain
Top achievements
Rank 1
answered on 31 Aug 2009, 09:17 PM
Has this issue been solved, I'm encountering the same problem, the report only shows on the page load but not on any subsequent data changes?

On my page load I set the report to the default data

protected void Page_Load(object sender, EventArgs e)  
    {  
      if (!IsPostBack)  
      {  
        this.RadDatePickerStartDate.SelectedDate = DateTime.Now;  
        this.RadDatePickerEndDate.SelectedDate = DateTime.Now;  
 
        DealerVisits dv = new DealerVisits();                  
        DealerReporting dr = new DealerReporting();  
                          
        dv.DataSource = dr.GetVisits(new Site().SiteKey, DateTime.Now,DateTime.Now);                                  
        this.ReportViewer1.Report = dv;                                  
      }  
    } 

 

 

 

However, if I try to update the datasource on a mouse click, the report never gets updated.  the status bar in the browser makes it appear something is happening but the report never changes.  I have tested multiple different time frames as well as using the same date as on the page load attempt.  When stepping through, the datasource is populated and the reportviewer report is set as "dv" but nothing ever changes in the browser.

 

 

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)  
    {  
      if (Page.IsValid)  
      {  
        DealerVisits dv = new DealerVisits();    
        DealerReporting dr = new DealerReporting();  
          
        dv.DataSource = dr.GetVisits(new Site().SiteKey, this.RadDatePickerStartDate.SelectedDate.Value, this.RadDatePickerEndDate.SelectedDate.Value);               
        this.ReportViewer1.Report = dv;  
      }  
    } 

0
Chavdar
Telerik team
answered on 02 Sep 2009, 08:47 AM
Hi Blain,

If you are using Q1 2009 (v3.0.9.311) release of Telerik Reporting then you have to set the EnableViewState property of the web ReportViewer to false. This issue has been fixed since the next version so you might also consider upgrading to a newer one.

Regards,
Chavdar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
General Discussions
Asked by
Nate Pinchot
Top achievements
Rank 1
Answers by
prismcarlson
Top achievements
Rank 1
Svetoslav
Telerik team
Yuvika
Top achievements
Rank 1
Charles Richardson
Top achievements
Rank 1
Steve
Telerik team
Grégoire
Top achievements
Rank 1
Chavdar
Telerik team
Adam
Top achievements
Rank 1
Blain
Top achievements
Rank 1
Share this question
or