I'm using Q2 2012 of Telerik reporting. I need to use the NeedDataSource event to populate my subreports. My subreports are populated by objects that inherit Reporting.Report. When I run the report, I get this error
An error has occurred while processsing Report 'Group' (my object)
An error has occurred while resolving '' data source: Object reference not set to an instance of an object.
this is my needDataSource
protected void needDataSource(object sender, EventArgs e)
{
Telerik.Reporting.Processing.ReportItemBase subreport = sender as Telerik.Reporting.Processing.ReportItemBase;
if (this.DataSource != null)
{
ods = new ObjectDataSource();
ods.DataSource = this.DataSource;
ods.DataMember = groupid;
ods.Parameters.Add(new ObjectDataSourceParameter(groupid));
subreport.Report.DataSource = ods;
}
}
Thanks in advance!
Gersh
An error has occurred while processsing Report 'Group' (my object)
An error has occurred while resolving '' data source: Object reference not set to an instance of an object.
this is my needDataSource
protected void needDataSource(object sender, EventArgs e)
{
Telerik.Reporting.Processing.ReportItemBase subreport = sender as Telerik.Reporting.Processing.ReportItemBase;
if (this.DataSource != null)
{
ods = new ObjectDataSource();
ods.DataSource = this.DataSource;
ods.DataMember = groupid;
ods.Parameters.Add(new ObjectDataSourceParameter(groupid));
subreport.Report.DataSource = ods;
}
}
Thanks in advance!
Gersh
5 Answers, 1 is accepted
0
Accepted
Hello Gersh,
It is not good idea to set data source of other data items (be it subreport, table or chart) in the NeedDataSource of the report. If you have to do this with code a valid approach would be the NeedDataSource of the subreport item itself:
If your scenario is different, please send us a runnable example with explanations what is it you're trying to achieve and we would advise you accordingly.
Kind regards,
Steve
the Telerik team
It is not good idea to set data source of other data items (be it subreport, table or chart) in the NeedDataSource of the report. If you have to do this with code a valid approach would be the NeedDataSource of the subreport item itself:
private
void
subReport1_NeedDataSource(
object
sender, EventArgs e)
{
Telerik.Reporting.Processing.SubReport subreport = sender
as
Telerik.Reporting.Processing.SubReport;
subreport.InnerReport.DataSource = ods;
}
If your scenario is different, please send us a runnable example with explanations what is it you're trying to achieve and we would advise you accordingly.
Kind regards,
Steve
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 >
0

Patrice
Top achievements
Rank 1
answered on 31 May 2017, 08:28 PM
In the main I've set the subreport's data using the
Private
Sub
subRptHeader_NeedDataSource(sender
As
Object
, e
As
EventArgs)
Handles
subRptHeader.NeedDataSource
TryCast(sender, Telerik.Reporting.Processing.SubReport).InnerReport.DataSource = pb
End
Sub
However, I cannot see, nor access, this when stepping through the subreport's code. I want to cast the back to the data object. But, when stepping into this, the is empty. This worked before upgrading from Q42014 to the current report code, and the deprecation of the report object.
Inherits
Telerik.Reporting.Report
Protected
Shared
_phaseBalanceWidthFor100Pct
As
Telerik.Reporting.Drawing.Unit
Protected
_pb
As
PanelBoard =
Nothing
Protected
ReadOnly
Property
pb()
As
PanelBoard
Get
If
NotSet(_pb)
Then
_pb =
CType
(
Me
.Report.DataSource, PanelBoard)
End
If
Return
_pb
End
Get
End
Property
0
Hello,
Below is a quote from my response to your inquiry in our support ticketing system:
You can set the DataSource of the processing report at run-time when the sub report requests its data (NeedDataSource event). In the sub report you will be able to access the data only through the processing report as the designed report's DataSource is not set (Me.DataSource) in order to have its NeedDataSource event fired.
You can create a user function accepting ReportItem.DataObject, where the function can be used in the sub report for getting its assigned data object.
If you need further help, please use one of both threads to share further details about the case.
Thank you for your understanding.
Regards,
Stef
Progress Telerik
Below is a quote from my response to your inquiry in our support ticketing system:
You can set the DataSource of the processing report at run-time when the sub report requests its data (NeedDataSource event). In the sub report you will be able to access the data only through the processing report as the designed report's DataSource is not set (Me.DataSource) in order to have its NeedDataSource event fired.
You can create a user function accepting ReportItem.DataObject, where the function can be used in the sub report for getting its assigned data object.
If you need further help, please use one of both threads to share further details about the case.
Thank you for your understanding.
Regards,
Stef
Progress Telerik
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 Feedback Portal
and vote to affect the priority of the items
0

Patrice
Top achievements
Rank 1
answered on 02 Jun 2017, 04:40 PM
I didn't need to use a function.
I simply caught the sender in the subReport, cast it to the appropriate processing object, and then used the object's .Report.DataSource to get the subreport's data.
I simply caught the sender in the subReport, cast it to the appropriate processing object, and then used the object's .Report.DataSource to get the subreport's data.
Private
Sub
detail_ItemDataBinding(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
detail.ItemDataBinding
Dim
ds =
DirectCast
(sender, Telerik.Reporting.Processing.DetailSection)
_pb =
CType
(ds.Report.DataSource, PanelBoard)
0
Hello,
Please check the updated Understanding Events help article to determine if this usage of events will not bring further issues.
We can also suggest you to test the data binding approaches from How to bind Sub Report to Main Report's Data and Change Sub Report based on Main Report's Data.
Regards,
Stef
Progress Telerik
Please check the updated Understanding Events help article to determine if this usage of events will not bring further issues.
We can also suggest you to test the data binding approaches from How to bind Sub Report to Main Report's Data and Change Sub Report based on Main Report's Data.
Regards,
Stef
Progress Telerik
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 Feedback Portal
and vote to affect the priority of the items