Quote tst = new Quote(); //Quote is the main report
Telerik.Reporting.ObjectDataSource odsHeader = (Telerik.Reporting.ObjectDataSource)tst.DataSource;
odsHeader.DataSource = cdtsQuote;
odsHeader.DataMember = "Header";
Telerik.Reporting.SubReport itemDetail = (Telerik.Reporting.SubReport)tst.Items.Find("srItemDetail", true)[0];
Telerik.Reporting.ObjectDataSource odsItems = (Telerik.Reporting.ObjectDataSource)itemDetail.ReportSource.DataSource;
odsItems.DataSource = cdtsQuote;
odsItems.DataMember = "OrderItems";
In the new version, the SubReport object's ReportSource has changed, so it doesn't have a DataSource property anymore. So, how do I go about setting the datasource? If I try setting the subreport's datasource via SubReport.Report.DataSource, it ends up re-setting the datasource of the master report, which causes even more problems.
Any ideas on how to accomplish this?
11 Answers, 1 is accepted
The ReportSource property of the SubReport has indeed changed and this gives you the possibility to assign a report not just by using a report instance, but also uri, xml, etc. For more information you can check our Report Sources help article.
Now because of these changes the ReportSource no longer exposes the properties you are used to and because of that you have to approach the issue in a different manner. In the case with the DataSource you will have to do it like this:
var tst =
new
Quote();
// Deal with the main report data source the same way
var itemDetail = (Telerik.Reporting.SubReport)tst.Items.Find(
"srItemDetail"
,
true
)[0];
var repSource = (InstanceReportSource)itemDetail.ReportSource;
// Because you know the ReportDocument is a Report;
var report = (Telerik.Reporting.Report)repSource.ReportDocument;
var odsItems = (Telerik.Reporting.ObjectDataSource)report.DataSource;
odsItems.DataSource = cdtsQuote;
odsItems.DataMember =
"OrderItems"
;
Also you have to know that the Report property is actually the containing report of the SubReport item and not the detail report assigned - this is just to be clear, although you probably figured it out on your own.
Kind regards,
IvanY
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 >
After hours of trying to fix my reports after the Q2 2012 update I still have a mess.
Can some one please tell me how to programmatically bind my subreports in this release.
My existing code was:
Dim rptLvlSex As Telerik.Reporting.SubReport = TryCast(rpt.Items.Find("SubLevelSex", True)(0), Telerik.Reporting.SubReport)
rptLvlSex.ReportSource.DataSource = dsCS
What is the new VB code that I need to use
Thank you
I sure hope Q2 2012 is worth the effort :-(
Update:
Ok while waiting around for a response I was able to get it to work.
Not sure if this is the perferred or best way, but it seems to work.
Dim rptLvlSex As Telerik.Reporting.SubReport = TryCast(rpt.Items.Find("SubLevelSex", True)(0), Telerik.Reporting.SubReport)
Dim iRS2 As Telerik.Reporting.InstanceReportSource = TryCast(rptLvlSex.ReportSource, Telerik.Reporting.InstanceReportSource)
Dim sub2 As Telerik.Reporting.Report = TryCast(iRS2.ReportDocument, Telerik.Reporting.Report)
sub2.DataSource = dsCS
This really doesn't seem like a very elegant solution with all this Casting, so if there is a better soloution, please let me know.
The Report Sources abstraction may seem as an obstacle at first, but once you check the help resources and grasp the main idea behind that abstraction you will see that it actually gives you more flexibility when you access your reports.
As reports can be stored anywhere there should exist an uniform way to access them - and this is exactly what Report Sources do. Previously the report viewers and the subreports were only able to use an instance of your report class. However this changed with the Report Sources, which now give you the opportunity to access your reports in the following ways:
- Instance - this is the way the reports used to be accessed before Q2 2012 (using and instance of your report class).
- Type - you can access your reports declaratively, only by specifying the type.
- URI - this gives you the option to load your report either from a file path or an Url
- XML - it can be used for reports stored in databases as pure XML and can be used like this: xmlReportSource.Xml = "=Fields.ReportXml"
Additionally you can check the How to migrate your project to utilize the new ReportSource objects KB article and the Report Sources help article which can give you a more detailed explanation about the Report Sources.
Greetings,
IvanY
the Telerik team
HAPPY WITH TELERIK REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!
I have a report which has a subreport defined referenced by a UriReportSource
I am using the RenderReport to create a PDF and I can loop through the main report and change any connection strings to a new connection string which allows me to have the same report but point it at different databases for different customers.
Problem I have is the sub report. As its a UriReportSource I cannot find any events to tap into to allow me to alter the connection strings for the Data sources when it gets rendered.
Would appreciate any help you can give as this is a major stumbling block.
Steve
Our advice is to is to utilize an user function to update the connection strings as shown in the following example:
public
static
SqlDataSource UpdateConnectionString(SqlDataSource dataSource)
{
dataSource.ConnectionString =
"New Connection String"
;
return
dataSource;
}
Then you have to add the following binding to the data items:
Property path |
Expression |
DataSource |
= UpdateConnectionString(ReportItem.ItemDefinition.DataSource) |
This binding will get the current data item data source component, execute the user function and bind the current report item to the updated data source component.
Additionally you may find useful the Extending Report Designer help article.
Peter
the Telerik team
Have you tried the new visualization options in Telerik Reporting Q1 2013? You can get them from your account.
Many thanks for the reply. I am a bit confused though.
I have two trdx files. One has the other as a sub report referenced by a UriReportSource. Where do I add the code for:
public
static
SqlDataSource UpdateConnectionString(SqlDataSource dataSource)
{
dataSource.ConnectionString =
"New Connection String"
;
return
dataSource;
}
Kind regards
Steve
How to extend the standalone report designer with user functions is elaborated in the Extending Report Designer help article.
Give it a try and let us know how it goes.
Peter
the Telerik team
Have you tried the new visualization options in Telerik Reporting Q1 2013? You can get them from your account.
Worked perfectly.
Thanks for your assistance.
Steve
When I tried your sample code above, this didn't work.
My following code after conversion is causing the following error.
Unable to cast object of type 'Telerik.Reporting.TypeReportSource' to type 'Telerik.Reporting.InstanceReportSource'.
Dim srReq = DirectCast(Me.Items.Find("srRequirements", True)(0), Telerik.Reporting.SubReport)
'This line is one erroring.
Dim repSource = DirectCast(srReq.ReportSource, InstanceReportSource)
Dim report = TryCast(repSource.ReportDocument, Telerik.Reporting.Report)
Dim odsItems = DirectCast(report.DataSource, Telerik.Reporting.ObjectDataSource)
odsItems.DataSource = Me.DataSource
odsItems.DataMember = "REQUIRED_RECS"
The previous code, below, before the ReportInstance worked fine for the subreport bindings.
I just can't seem to figure how to bind this .
Me.SupplierSubRequirement1.Bindings.Add(New Telerik.Reporting.Binding("DataSource", "=Fields.REQUIRED_RECS"))
It will not be possible to convert TypeReportSource to InstanceReportSource. To make modifications to the sub report instance you can create a new sub report, access/modify its properties and then set it as ReportSource for the SubReport item:
Dim
mainReportInstance =
New
MasterReport()
Dim
subreportItem = TryCast(mainReportInstance.Items.Find(
"subReport1"
,
True
)(0), Telerik.Reporting.SubReport)
Dim
subreport =
New
SubReport1()
subreport.DataSource = "new data source"
subreportItem.ReportSource =
New
InstanceReportSource()
With
{ _
Key .ReportDocument = subreport _
}
Regards,
Katia
Progress Telerik