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

master-detail data using sub reports

4 Answers 293 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kushan
Top achievements
Rank 1
Kushan asked on 26 Aug 2008, 03:51 PM

Hi,

I’m trying to display some master-detail data on a report. I have designed two separate reports and linking the detail report to a sub report item in the detail section of the master report. But the detail report (for any master row) is always displaying the records related to the first master row. Code I’m using is similar to below. Can you please help solving this.

Thanks and regards,

Kushan

 

MasterReport  masterReport  =  new  MasterReport();

DataTable  masterDataSource  =  getMasterDataSource();

Foreach(DataRow drM  in  masterDataSource.Rows)

{

   FormatMasterRows(drM);

   DataTable  detailDataSource  =  getDetailDataSource(drM);

   If(detailDataSource.RowCount > 0)

   {

            DetailReport  detailReport  =  new DetailReport();

            Foreach(DataRow  drD  in detailDataSource.Rows)

            {

               FormatDetailRows(drD);

            }

            detailReport.DataSource  =  detailDataSource;

            masterReport.subReportItem1.ReportSource  =  detailReport;

            masterReport.subReportItem1.ReportSource  =  true;      

   }

   Else

  {

            masterReport.subReportItem1.ReportSource  =  false;

            masterReport.detailSection.Height  =  masterReport.detailSection.Height   -  masterReport.subReportItem1.Height;

  }

}

masterReport.DataSource  =  drM;

DisplayRepotViewer(masterReport);

4 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 27 Aug 2008, 10:13 AM
Hi Kushan,

It is not correct to use true/false for subReportItem1.ReportSource. You have to either specify a report for it (i.e.
subReportItem1.ReportSource  =  detailReport;) or set it to null when it has to be empty. A nice forum thread that elaborates on master-detail report is discussed here.
You can also review the help topic available in our documentation: Creating Master-Detail Reports Using SubReports.

Best wishes,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Kushan
Top achievements
Rank 1
answered on 27 Aug 2008, 12:11 PM
Thanks Steve.

It's a typo and should be corrected as 
masterReport.subReportItem1.Visible  =  true;

But my problem is to include a sub report in the master reports detail section? When the report runs each row should have a sub report populated with data and I couldn't figureout a way to link different instance of a sub report per master row.

Cheers,
Kushan

0
Kushan
Top achievements
Rank 1
answered on 27 Aug 2008, 12:22 PM
Ideal out put should be like this.


Id:             Master_Rec1

Name:     GFHFGHFGHH45368

Value:     Gsdsdsdfdsfd

History:

Id

Name

Value

Detail_Rec1_For_Master_Rec1

GFHFGHFGHH45368

XFGFDgfgerew

Detail_Rec2_For_Master_Rec1

GFHFGHFGHH45368

KKKKKSDFDSFDF

Id:             Master_Rec2

Name:     GFHFGHFGHH111111

Value:     This master record don’t have any detail records and the sub table should not be visble!

Id:             Master_Rec3

Name:     GFHFGHFGHH999999

Value:     Horasflknsafksf

History:

Id

Name

Value

Detail_Rec1_For_Master_Rec3

GFHFGHFGHH999999

OOOOOOOpsssss

Detail_Rec2_For_Master_Rec3

GFHFGHFGHH999999

JKFdsfdfhdjdjfhdjfh

0
Ivan
Telerik team
answered on 29 Aug 2008, 03:57 PM
Hi Kushan,

From the code snippet you have provided it is not clear why the detail rows in the sub-report are not displayed correctly. In fact such a master-detail relationship between reports is a pretty common case and should not involve any coding from you at all, as long as a proper filter is specified in the detail report. Have you tried to follow the instructions described in this help topic to verify you have not missed something important?

I have attached a small test project with a report that looks similar to the report you are trying to achieve. A more sophisticated example of a report using sub-reports can be found in this online demo.

If you need additional help with the sub-reports, please, do not hesitate to ask!

 
Kind regards,

the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Kushan
Top achievements
Rank 1
Answers by
Steve
Telerik team
Kushan
Top achievements
Rank 1
Ivan
Telerik team
Share this question
or