
'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

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.

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

You suggested the following: MyReport myReport = new MyReport(); |
myReport.DataSource = ds; |
this.reportViewer1.Report = myReport; |

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

@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.

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 |
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.

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> |

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; |
} |
} |
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.