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

How to manage the Multiple datasource in Subreport

2 Answers 311 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Siva
Top achievements
Rank 1
Siva asked on 30 Jul 2012, 06:05 PM
Hi 
i have 1 report with 2 subreports. one of the subreport has 2 sqldatasources. based on the main reports fields pick the datasource out of 2 .

i am ausing needdatasource event in subreport like.
 private void StateErrorsAtAGlance_DetailHeader_NeedDataSource(object sender, EventArgs e)
        {
            Telerik.Reporting.Processing.Report report = (Telerik.Reporting.Processing.Report)sender;
            if (report.Parameters["HeaderType"].Value.ToString().Equals("Agency Error"))
            {
                this.DataSource = this.sqlDataSource1;
            }
            else
            {
                this.DataSource = this.sqlDataSource2;
            }
        }
when run the main report returns 3 field , 1 agency Error, Client Error and No error.
but subreport gives result only agency error row remaing rows like Client error and No error it picks design time parameter values,
that's it shows All zeros.

i observed when debug the subreport needdatasource events calls only one time, how it 'll manage when main reports have 4 records



2 Answers, 1 is accepted

Sort by
0
IvanY
Telerik team
answered on 02 Aug 2012, 11:40 AM
Hi Siva,

The NeedDataSource events of the Report and the SubReport are called only once and that is by design - a Report can have only one data source attached and therefore if it does not have any the NeedDataSource event handler is invoked. Of course it is invoked only once because the Report needs only one data source.

If you happen to have a report that needs more than one data source you actually need more than one data item (such as table, chart, subreport, etc.).

If the case is that you have 4 SubReports you will have to add a NeedDataSource event handler for each of these items and attach data source for each of them separately. If the code for all of them is the same you can extract it in a method.

For more information please check the Using NeedDataSource event to connect data help article.

If your setup is different please elaborate or better yet - send us a runnable sample that exhibits the issue - that way we will be able to view it locally and advise you more accordingly.

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 >

0
Siva
Top achievements
Rank 1
answered on 06 Sep 2012, 02:01 PM
It works fine when i was using ItemdataBinding event  instead of  NeedDataSiurce event

Thanks
Siva
Tags
General Discussions
Asked by
Siva
Top achievements
Rank 1
Answers by
IvanY
Telerik team
Siva
Top achievements
Rank 1
Share this question
or