This is a migrated thread and some comments may be shown as answers.

problem binding datasource to subreport

4 Answers 377 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Michele
Top achievements
Rank 2
Michele asked on 27 Aug 2009, 02:23 PM
Hello,
I've got a dataset with 7 table, I've filled the main report page with the data of DataSet.Tables[0], but I'm not able to see the other data in the subreport... I've setted the membersource inside the report to the corresponding column.... anyone can provide me a sample with the how-to?
Thanks

4 Answers, 1 is accepted

Sort by
0
Michele
Top achievements
Rank 2
answered on 27 Aug 2009, 03:38 PM
I've investigated further, I've set all kind of event handlers and tried to set the dataset to the subreport... but it seems that the databinding of the subreport is called before the main report binding...and also I've got no pass from NeedDataSource events (in Main Report nor in Subreport)

I think the problem is really simple... but I find no way..
thanks
0
Steve
Telerik team
answered on 27 Aug 2009, 04:22 PM
Hello Paolo,

As you've probably figured out, a Telerik Report can be bound to a single table only. If you need to use data from others, you need to use SubReport or Table/Crosstab/List items. The first one is used to show a separate report inside the main report, while the table item is a separate data region that can be bound to a separate data from the report it resides in. Also as explained in the Adding a Data Source through NeedDataSource report event help article, the NeedDataSource event of a report is fired only if the report does not have datasource set. The same goes for the NeedDataSource event of the subreport item - it is fired only when the report used as ReportSource does not have datasource set.

All the best,
Steve
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.
0
Michele
Top achievements
Rank 2
answered on 28 Aug 2009, 07:48 AM
Hello Steve,
I've tried to do what you told me and I set the datasource in this way :

   private void subReport1_NeedDataSource(object sender, EventArgs e)  
        {  
            Telerik.Reporting.Processing.SubReport sub = (Telerik.Reporting.Processing.SubReport)sender;  
 
            if(sub != null)  
            {  
                sub.Report.DataSource = (this.DataSource as DataSet).Tables[3];  
            }  
        }  
 

it sets the DataSource correctly but it doesn't show the data (I use this in the Main Report, in the SubReport I removed the DataMember and DataSource)

If I use a Property in the subreport, then I assign the datasource in the .aspx (keeping DataMember and DataSource set in the subreport) it works...



another OT question ... I need to show a 'Yes'/'NO' based on a boolean... what's the exact syntax? I found no sample in the documentation ... i tried with =IF(Fields.CAMPO = 1) THEN 'yes' ELSE 'no' but it doesn't work...


Thanks
Paolo
0
Steve
Telerik team
answered on 28 Aug 2009, 12:45 PM
Hello Paolo,

Maybe the confusion comes from the fact that both the subreport item and report used as subreport have NeedDataSource events. This is by design and both approaches can be used for different cases:
  • Using the NeedDataSource event of the SubReport item: This method is appropriate in the case child report is shared between more than one master reports. The child report DataSource should be null, thus signaling the reporting engine to raise NeedDataSource event.The event handler will reside in the Master report definition class. The handler would look like this:

    Telerik.Reporting.Processing.SubReport subReportItem = sender as Telerik.Reporting.Processing.SubReport;
    subReportItem.InnerReport.DataSource = <your datasource>;
  • Using the NeedDataSource event for the Child report: Again the child report DataSource property should be null. The handler looks like:

    Telerik.Reporting.Processing.Report report= sender as Telerik.Reporting.Processing.Report;
    Telerik.Reporting.Processing.SubReport subReportItem = report.Parent as Telerik.Reporting.Processing.SubReport;
    report.DataSource = <your datasource>;
Note that in the first case you access the child report via the InnerReport property, while in the second the child report is the sender.

As for your second question, you can use the IIF function in the Edit Expression Dialog directly for such purposes, e.g.:

= IIf(Fields.CAMPO = 1, 'Yes', 'No')

Regards,
Steve
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.
Tags
General Discussions
Asked by
Michele
Top achievements
Rank 2
Answers by
Michele
Top achievements
Rank 2
Steve
Telerik team
Share this question
or