Hi,
I am using Reporting Q1 2011 and am trying to make a report that contains a subreport. I am using a ObjectDataSource for this report. I am not setting the datasource for the subreport, I am using the NeedDataSource event to do that. Problem is, I can't figure out how to refer to the element I need. I downloaded an example from this site http://www.telerik.com/community/forums/reporting/telerik-reporting/sample-for-master-detail-using-object-collection-as-datasource.aspx that shows how to do this, but it's from an older version and the .DataItem property is no longer available. I can't seem to find a current example of how to do this. So how exactly does one gain access to dataitems in a business object so that the datasource of the subreport can be set correctly using Q1 2011?
Thanks
I am using Reporting Q1 2011 and am trying to make a report that contains a subreport. I am using a ObjectDataSource for this report. I am not setting the datasource for the subreport, I am using the NeedDataSource event to do that. Problem is, I can't figure out how to refer to the element I need. I downloaded an example from this site http://www.telerik.com/community/forums/reporting/telerik-reporting/sample-for-master-detail-using-object-collection-as-datasource.aspx that shows how to do this, but it's from an older version and the .DataItem property is no longer available. I can't seem to find a current example of how to do this. So how exactly does one gain access to dataitems in a business object so that the datasource of the subreport can be set correctly using Q1 2011?
Thanks
4 Answers, 1 is accepted
0

Tavo
Top achievements
Rank 1
answered on 13 Jul 2011, 04:32 AM
hi there, i hope still you're needing it, the code need some changes on the types, instead use Telerik.Reporting.Processing.SubReport try using Telerik.Reporting.Processing.ReportItemBase in the same event. i mean:
private void subReport_NeedDataSource(object sender, EventArgs e)
{
Telerik.Reporting.Processing.ReportItemBase subReportItem = sender as Telerik.Reporting.Processing.ReportItemBase;
// get the current row of data
subReportItem.ItemDefinition.Report.DataSource = yourCollention;
}
private void subReport_NeedDataSource(object sender, EventArgs e)
{
Telerik.Reporting.Processing.ReportItemBase subReportItem = sender as Telerik.Reporting.Processing.ReportItemBase;
// get the current row of data
subReportItem.ItemDefinition.Report.DataSource = yourCollention;
}
0

John
Top achievements
Rank 1
answered on 13 Jul 2011, 03:09 PM
Hi Tavo,
Thanks for your input, but It's still not clear at all how to link the datasource to an element in the parent datasource. My business object is as such:
internal class CompanyData
{
public IList<DepartementData> departments;
public CompanyData(string name, string address)
{
CompanyName = name;
}
public string CompanyName { get; set; }
public IList<DepartementData> Departments
{
get { return departments; }
}
}
internal class Companies : List<CompanyData>
{
public Companies()
{
CompanyData cd;
cd = new CompanyData("A");
cd.departments = new Departements();
Add(cd);
cd = new CompanyData("B");
cd.departments = new Departements();
Add(cd);
}
}
// Departments
internal class DepartementData
{
public DepartementData(string name)
{
DepartementName = name;
}
public string DepartementName { get; set; }
}
internal class Departements : List<DepartementData>
{
public Departements()
{
DepartementData d;
d = new DepartementData("Team1");
Add(d);
d = new DepartementData("Team2");
Add(d);
}
}
My main report has it's datasource pointing to the CompanyData object. The subreport will have to have it's datasource pointing to the CompanyData.Departments IList. In the subReport_NeedDataSource event I have to assign the datasource to this CompanyData.Departments that is currently being used by the parent report. You say use 'yourcollection'. OK, but how do I reference my collection when this event is called? I assume that I have to reference the datasource of the main report and then point to the Departments collection of that, but where is it?
Now I'm totally confused!?!
Thanks for your input, but It's still not clear at all how to link the datasource to an element in the parent datasource. My business object is as such:
internal class CompanyData
{
public IList<DepartementData> departments;
public CompanyData(string name, string address)
{
CompanyName = name;
}
public string CompanyName { get; set; }
public IList<DepartementData> Departments
{
get { return departments; }
}
}
internal class Companies : List<CompanyData>
{
public Companies()
{
CompanyData cd;
cd = new CompanyData("A");
cd.departments = new Departements();
Add(cd);
cd = new CompanyData("B");
cd.departments = new Departements();
Add(cd);
}
}
// Departments
internal class DepartementData
{
public DepartementData(string name)
{
DepartementName = name;
}
public string DepartementName { get; set; }
}
internal class Departements : List<DepartementData>
{
public Departements()
{
DepartementData d;
d = new DepartementData("Team1");
Add(d);
d = new DepartementData("Team2");
Add(d);
}
}
My main report has it's datasource pointing to the CompanyData object. The subreport will have to have it's datasource pointing to the CompanyData.Departments IList. In the subReport_NeedDataSource event I have to assign the datasource to this CompanyData.Departments that is currently being used by the parent report. You say use 'yourcollection'. OK, but how do I reference my collection when this event is called? I assume that I have to reference the datasource of the main report and then point to the Departments collection of that, but where is it?
Now I'm totally confused!?!
0

Tavo
Top achievements
Rank 1
answered on 13 Jul 2011, 04:00 PM
hi John , well first you must to associate your main report to a viwer, using this inside the function that you used to call the main report:
(This code is using on the call to the main report)
YourMainReport mainReport = new YourMainReport ();
additional to this i'm suggest to add a public property to your main report the type Ilist<Departament> to make easier
the spread from the list coming from the main call (this line: mainReport.lisOfDepartaments = listofDepartaments;)
you must to add to the object subreport the event NeedDataSource the next code:
(This code is using at the main report)
public Ilist<Departament> lisOfDepartaments;
private void subReportInsideMainReport_NeedDataSource(object sender, EventArgs e)
{
Telerik.Reporting.Processing.ReportItemBase subReportItem = sender as Telerik.Reporting.Processing.ReportItemBase;
// get the current row of data
subReportItem.ItemDefinition.Report.DataSource = lisOfDepartaments;
}
(This code is using on the call to the main report)
YourMainReport mainReport = new YourMainReport ();
mainReport.DataSource = objectCompanyData;
mainReport.lisOfDepartaments = objectCompanyData.Departaments;
this.ReportViewer.Report = reporteMostrar;
additional to this i'm suggest to add a public property to your main report the type Ilist<Departament> to make easier
the spread from the list coming from the main call (this line: mainReport.lisOfDepartaments = listofDepartaments;)
you must to add to the object subreport the event NeedDataSource the next code:
(This code is using at the main report)
public Ilist<Departament> lisOfDepartaments;
private void subReportInsideMainReport_NeedDataSource(
{
Telerik.Reporting.Processing.
// get the current row of data
subReportItem.ItemDefinition.
}
0

John
Top achievements
Rank 1
answered on 14 Jul 2011, 03:49 PM
Hi Tavo,
I was still having some difficulty following your logic. In the mean time, I opened a support ticket on the same issue. The answer is very elegant and simple.
Simply set the SubReport control binding to =Field.Departments. No events are needed (in fact, they are discouraged in this case).
That's it. Simple and it works.
Thank you for your help.
-John
I was still having some difficulty following your logic. In the mean time, I opened a support ticket on the same issue. The answer is very elegant and simple.
Simply set the SubReport control binding to =Field.Departments. No events are needed (in fact, they are discouraged in this case).
That's it. Simple and it works.
Thank you for your help.
-John