I stepped through the report event and noted that the NeedDataSource fires whenever I press preview from the Report viewer. I do notice however, that the NeedDataSource event fires again when I do an export from the report viewer. This event is where I set the report.DataSource, this also means that this is where I run the database queries.
I would have thought that since the report.DataSource has already been set/cached during the "preview" action (through the NeedDataSource), the "export to excel" action will not cause the NeedDataSource event to fire again. This is a winforms application by the way so asp.net statelessness is not an issue.
You see, I have a fairly large monthly data set and it takes twice the time to preview the report and export the report because of this NeedDataSource event.
How is the NeedDataSource event triggered? What sets the report.Datasource to nothing?
An example of the NeedDataSource event:
Private Sub MonthlyAccepted_AS_MasterReport_NeedDataSource(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.NeedDataSource
Dim subGroupName As ISOSettlementProvisionSubGroupName = EnumUtility(Of ISOSettlementProvisionSubGroupName).Parse(Me.ReportParameters(SETTLEMENT_TYPE).Value)
Dim dayofMonth As Date = Date.Parse(Me.ReportParameters(MONTH).Value & " 1, " & Me.ReportParameters(YEAR).Value)
me.DataSource = BusinessObjects.MonthlyAcceptedASInfo.GetData(dayofMonth, subGroupName)
End Sub
Thanks.
5 Answers, 1 is accepted
Indeed, this is the way in which Telerik Reporting is working at the moment. Please, consider the following workaround as a possible solution for now:
Dim oldValueParam1 As Object |
Dim oldValueParam2 As Object |
Dim currentDataSource As Object |
Private Sub Report1_NeedDataSource(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.NeedDataSource |
Dim processingReport = CType(sender, Telerik.Reporting.Processing.Report) |
If (currentDataSource Is Nothing) Or (oldValueParam1 <> Me.ReportParameters(0).Value) Or (oldValueParam2 <> Me.ReportParameters(1).Value) Then |
currentDataSource = New Object(3) {1, 2, 3, 4} 'Get new data and cache it. |
oldValueParam1 = Me.ReportParameters(0).Value |
oldValueParam2 = Me.ReportParameters(1).Value |
End If |
processingReport.DataSource = currentDataSource |
End Sub |
Kind regards,
Chavdar
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.

Hello,
I have encountered a similar problem. I have generated a report programatically an now I want to export it
in two different formats: pdf and rtf.
The scenario is as follows:
Telerik.Reporting.Report generatedReport = GenerateReport(structureParameters);
if (generatedReport.Export("PDF"))
{
try
{
generatedReport.Export(reportName, "RTF");
}
catch (Exception ex)
{
//handle exception
}
}
The pdf file output is as expected, but the rtf file has several issues on charts that use the NeedDataSource event.
I have tried to export it in rtf format first and then in pdf. The scenario was similar - the rtf was generated ok but the pdf is generated with no data in the Charts.
Do you have any workaround to fix this situation?
The datasource of the report is quite large (each report datasource is obtained by calling a stored procedure which returns multiple result sets), therefore we cannot afford to create a new report object for each rendering extension in order to avoid this problem.
I want to mention that we are using the Q1 SP1 2009 version.
Best regards,
Daniel

I could provide a sample project, but I think the problem is pretty straight forward: Create a report and render it at once in PDF and RTF (in this order). You'll notice that a chart whose datasource is bound in the NeedDataSource event like below will display correctly in PDF but will display "There is no or empty series" in RTF.
Please let me know if you are able to reproduce the issue and if you have any workarounds, so I know how to handle it for our next release.
private DataTable dataTable = null;
public Report1()
{
/// <summary>
/// Required for telerik Reporting designer support
/// </summary>
InitializeComponent();
dataTable = GetSampleDataSource();
}
private void chart1_NeedDataSource(object sender, EventArgs e)
{
Telerik.Reporting.Processing.Chart chart = sender as Telerik.Reporting.Processing.Chart;
Telerik.Reporting.Chart chartDefinition = chart.ItemDefinition as Telerik.Reporting.Chart;
Telerik.Reporting.Charting.ChartSeries chartSeries1 = new Telerik.Reporting.Charting.ChartSeries();
Telerik.Reporting.Charting.ChartSeries chartSeries2 = new Telerik.Reporting.Charting.ChartSeries();
....... other series
chart.DataSource = dataTable;
........ etc
}
You'll notice that GetSampleDataSource() is olny called once in the Constructor and caches the datasource. However, it seems that on the second call to the chart1_NeedDataSource method (when rendering the RTF) the chart's datasource is not properly set.
Update: I have opened a support ticket for this problem.
When the report is rendered twice, the NeedDataSource event of the chart will be also raised two times. You have to make sure that the chart definition is configured correctly on each NeedDataSource event. For example if you are adding chart series dynamically then make sure that they are not added again (for the second time) at the second NeedDataSource event. Also, please make sure that you are passing a correct data source each time. If the problem still persists, please make a simple stand-alone project which replicates this behavior and send it to us through a support ticket.
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.

So, the solution was to initialize the chart only once in the constructor (series, color palette, etc) and leave in the NeedDataSource event of the chart only the dynamic part (which in my case was setting the DataSource property of the Processing Chart object to the cached datasource like below).
private void chart1_NeedDataSource(object sender, EventArgs e)
{
(sender as Telerik.Reporting.Processing.Chart).DataSource = cachedDataSource;
}
All the best,
Daniel