Henrique Duarte
Top achievements
Rank 1
Veteran
Henrique Duarte
asked on 06 Mar 2008, 06:00 PM
How can I pass the datasource to a subreport from a page?
Ex: "ReportViewer1.Report.SubReport.DataSource = ds"
[]'s
Henrique
9 Answers, 1 is accepted
0
Accepted
Hello Henrique Duarte,
Accessing the subreport's data source from the report's methods (event handlers, properties and other methods) is not a problem. It should look something like:
this.subReport1.ReportSource.DataSource = myDataSourceObject;
But report designer creates all the report items private and we should change their accessibility or provide a public property/method to access them outside - for example:
Please let me know if you have any other questions.
Kind regards,
Ivan
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Accessing the subreport's data source from the report's methods (event handlers, properties and other methods) is not a problem. It should look something like:
this.subReport1.ReportSource.DataSource = myDataSourceObject;
But report designer creates all the report items private and we should change their accessibility or provide a public property/method to access them outside - for example:
// a part of the class code |
class Report1 |
{ |
private SubReport subReport1; |
public object DataSourceOfSubreport1 |
{ |
set { this.subReport1.ReportSource.DataSource = value; } |
} |
public string DataMemberOfSubreport1 |
{ |
set { this.subReport1.ReportSource.DataMember = value; } |
} |
} |
// And later in the Form's code: |
private void button1_Click(object sender, EventArgs e) |
{ |
(this.reportViewer1.Report as Report1).DataSourceOfSubreport1 = myDataSourceObject; |
} |
Please let me know if you have any other questions.
Kind regards,
Ivan
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Zed
Top achievements
Rank 1
answered on 23 Aug 2008, 03:33 PM
I cannot seem to get the subreport to load on the first PAGE_Load event. Your example shows the subreport being populated only on postback. Must it be this way or can you get it on the the first page_load?
0
Hello Zed,
You can use the provided in the previous post code snippet without any problems in the Page_Load event of the page as well. For example the following code should work as expected:
protected void Page_Load(object sender, EventArgs e)
{
Report1 report = new Report1();
report.DataSourceOfSubreport1 = myDataSourceObject;
this.ReportViewer1.Report = report;
}
If you experience any problems with this approach, please let us know exactly what your task is and the desired behaviour you want to achieve.
Regards,
Chavdar
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
You can use the provided in the previous post code snippet without any problems in the Page_Load event of the page as well. For example the following code should work as expected:
protected void Page_Load(object sender, EventArgs e)
{
Report1 report = new Report1();
report.DataSourceOfSubreport1 = myDataSourceObject;
this.ReportViewer1.Report = report;
}
If you experience any problems with this approach, please let us know exactly what your task is and the desired behaviour you want to achieve.
Regards,
Chavdar
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
James
Top achievements
Rank 2
answered on 06 Nov 2008, 09:50 PM
I am using VB.net instead of C#, and I added a public property to my master report code-behind like this:
But in the page load event of the page that contains my reportviewer I cannot set this property after setting the datasource for the main page like this:
The main report is working great, I cannot get the data to load in the subreport, and I have tried this in the Page.load event of the page containing the reportviewer:
Thanks in advance for your response.
Public Property DataSourceOfSubReport1() As DataSet |
Get |
Return Me.SubReport1.ReportSource.DataSource |
End Get |
Set(ByVal value As DataSet) |
Me.SubReport1.ReportSource.DataSource = value |
End Set |
End Property |
Public Property DataMemberOfSubReport1() As String |
Get |
Return Me.SubReport1.ReportSource.DataMember |
End Get |
Set(ByVal value As String) |
Me.SubReport1.ReportSource.DataMember = value |
End Set |
End Property |
But in the page load event of the page that contains my reportviewer I cannot set this property after setting the datasource for the main page like this:
Dim mainRpt As Report = New TelerikReports.PickTicket() |
mainRpt.DataSource = Me._dsPickTicket |
mainRpt.DataMember = "PickTicketHeader" |
The main report is working great, I cannot get the data to load in the subreport, and I have tried this in the Page.load event of the page containing the reportviewer:
Dim subRptItemDtl As Report = New TelerikReports.PickTicketDetail() |
subRptItemDtl.DataSource = Me._dsPickTicket |
subRptItemDtl.DataMember = "PickTicketDetail" |
Thanks in advance for your response.
0
Hello James,
It seems that you do not use the public properties that you've exposed in the Report class. Please review the post of my colleague Ivan carefully and let us know if still having problems.
Best wishes,
Steve
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
It seems that you do not use the public properties that you've exposed in the Report class. Please review the post of my colleague Ivan carefully and let us know if still having problems.
Best wishes,
Steve
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
James
Top achievements
Rank 2
answered on 07 Nov 2008, 04:29 PM
Steve,
I was able to get it working by doing the following in my vb.net code:
I have run across another issue and posted the info in this post:
Main post
I will quit posting on this thread, and thanks for responding here!
I was able to get it working by doing the following in my vb.net code:
Dim mainRpt As Report = New TelerikReports.PickTicket() |
Dim objPickTicket As PickTicket = mainRpt |
mainRpt.DataSource = Me._dsPickTicket |
mainRpt.DataMember = "PickTicketHeader" |
objPickTicket.DataSourceOfSubReport1 = Me._dsPickTicket |
objPickTicket.DataMemberOfSubReport1 = "PickTicketDetail" |
I have run across another issue and posted the info in this post:
Main post
I will quit posting on this thread, and thanks for responding here!
0
Arun
Top achievements
Rank 1
answered on 04 Apr 2013, 11:31 AM
Hi,
I have one doubt,
I am using telerik reporting version 6.1.12.820.
I have one subreport and one main report. subreport values to binding the main report. i am using code below,
Telerik.Reporting.SubReport subReport2 = (Telerik.Reporting.SubReport)poReport.Items.Find("subReport2", true)[0];
subReport2.ReportSource.DataSource = pMaster;
it will show error, ('Telerik.Reporting.ReportSource' does not contain a definition for 'DataSource' and no extension method 'DataSource' accepting a first argument of type 'Telerik.Reporting.ReportSource' could be found (are you missing a using directive or an assembly reference?).
Advance Thanks
I have one doubt,
I am using telerik reporting version 6.1.12.820.
I have one subreport and one main report. subreport values to binding the main report. i am using code below,
Telerik.Reporting.SubReport subReport2 = (Telerik.Reporting.SubReport)poReport.Items.Find("subReport2", true)[0];
subReport2.ReportSource.DataSource = pMaster;
it will show error, ('Telerik.Reporting.ReportSource' does not contain a definition for 'DataSource' and no extension method 'DataSource' accepting a first argument of type 'Telerik.Reporting.ReportSource' could be found (are you missing a using directive or an assembly reference?).
Advance Thanks
0
Hi,
The SubReport.ReportSource property can get value from any of the listed report source objects, and these report source objects contain a reference to a report definition (or the definition itself) and can pass parameters to it. The data is passed to the report document directly through the Report.DataSource property. In your case you need to use InstanceReportSource. You can find attached a sample Win Forms project illustrating the described (Form1.cs)
I hope this helps.
Greetings,
Stef
the Telerik team
The SubReport.ReportSource property can get value from any of the listed report source objects, and these report source objects contain a reference to a report definition (or the definition itself) and can pass parameters to it. The data is passed to the report document directly through the Report.DataSource property. In your case you need to use InstanceReportSource. You can find attached a sample Win Forms project illustrating the described (Form1.cs)
I hope this helps.
Greetings,
Stef
the Telerik team
Have you tried the new visualization options in Telerik Reporting Q1 2013? You can get them from your account.
0
Arun
Top achievements
Rank 1
answered on 10 Apr 2013, 06:21 PM
Hello Stef,
Thank you very much for your response. Your attachment file very helpful for me. I understood clear.
Now my issue is clear. Once again thanks.
Regards
Arun
Thank you very much for your response. Your attachment file very helpful for me. I understood clear.
Now my issue is clear. Once again thanks.
Regards
Arun