1,创建DataSet
2,将字段绑定(拖动)到子报表
3,将子报表加入到主报表中(省略了主报表部分的初始化)
//
create the relation of main report and the child report
ISCDReportClientDocument rptClientDoc = _rptContainerDoc.ReportClientDocument;
// Section define the character of this Section.
// it contains type, name, width, height and so on.
CrystalDecisions.ReportAppServer.ReportDefModel.Section xSection = new CrystalDecisions.ReportAppServer.ReportDefModel.Section();
xSection.Kind = CrystalDecisions.ReportAppServer.ReportDefModel.CrAreaSectionKindEnum.crAreaSectionKindReportFooter;
xSection.Name = " xxx " ;
xSection.Width = 567 * 10 ;
xSection.Height = 567 * 20 ;
// position and import report file
CrystalDecisions.ReportAppServer.ReportDefModel.ISCRArea xArea = rptClientDoc.ReportDefController.ReportDefinition.ReportFooterArea;
rptClientDoc.ReportDefController.ReportSectionController.Add(xSection, xArea, - 1 );
SubreportClientDocument subRptClientDoc = rptClientDoc.SubreportController.ImportSubreport( " test " , strPath, xSection);
// Section define the character of this Section.
CrystalDecisions.ReportAppServer.ReportDefModel.Section xSection2 = new CrystalDecisions.ReportAppServer.ReportDefModel.Section();
xSection2.Kind = CrystalDecisions.ReportAppServer.ReportDefModel.CrAreaSectionKindEnum.crAreaSectionKindReportFooter;
xSection2.Name = " xxxg " ;
xSection2.Width = 567 * 10 ;
xSection2.Height = 567 * 20 ;
// position and import report file
rptClientDoc.ReportDefController.ReportSectionController.Add(xSection2, xArea, - 1 );
subRptClientDoc = rptClientDoc.SubreportController.ImportSubreport( " test22 " , strPath, xSection2);
DataSetSingle dsSingle = new DataSetSingle();
dsSingle.tblSingle.AddtblSingleRow( " 1 " , " 111 " );
dsSingle.tblSingle.AddtblSingleRow( " 2 " , " 222 " );
dsSingle.tblSingle.AddtblSingleRow( " 3 " , " 333 " );
dsSingle.tblSingle.AddtblSingleRow( " 4 " , " 444 " );
// subRptClientDoc.DatabaseController.AddDataSource(DataSetConverter.Convert(dsSingle));
// visit child reports and databind
_rptContainerDoc.Subreports[ 0 ].SetDataSource(dsSingle);
dsSingle.tblSingle.AddtblSingleRow( " 1 " , " 111 " );
dsSingle.tblSingle.AddtblSingleRow( " 2 " , " 222 " );
dsSingle.tblSingle.AddtblSingleRow( " 3 " , " 333 " );
dsSingle.tblSingle.AddtblSingleRow( " 4 " , " 444 " );
/// /visit child reports and databind
_rptContainerDoc.Subreports[ 1 ].SetDataSource(dsSingle);
ISCDReportClientDocument rptClientDoc = _rptContainerDoc.ReportClientDocument;
// Section define the character of this Section.
// it contains type, name, width, height and so on.
CrystalDecisions.ReportAppServer.ReportDefModel.Section xSection = new CrystalDecisions.ReportAppServer.ReportDefModel.Section();
xSection.Kind = CrystalDecisions.ReportAppServer.ReportDefModel.CrAreaSectionKindEnum.crAreaSectionKindReportFooter;
xSection.Name = " xxx " ;
xSection.Width = 567 * 10 ;
xSection.Height = 567 * 20 ;
// position and import report file
CrystalDecisions.ReportAppServer.ReportDefModel.ISCRArea xArea = rptClientDoc.ReportDefController.ReportDefinition.ReportFooterArea;
rptClientDoc.ReportDefController.ReportSectionController.Add(xSection, xArea, - 1 );
SubreportClientDocument subRptClientDoc = rptClientDoc.SubreportController.ImportSubreport( " test " , strPath, xSection);
// Section define the character of this Section.
CrystalDecisions.ReportAppServer.ReportDefModel.Section xSection2 = new CrystalDecisions.ReportAppServer.ReportDefModel.Section();
xSection2.Kind = CrystalDecisions.ReportAppServer.ReportDefModel.CrAreaSectionKindEnum.crAreaSectionKindReportFooter;
xSection2.Name = " xxxg " ;
xSection2.Width = 567 * 10 ;
xSection2.Height = 567 * 20 ;
// position and import report file
rptClientDoc.ReportDefController.ReportSectionController.Add(xSection2, xArea, - 1 );
subRptClientDoc = rptClientDoc.SubreportController.ImportSubreport( " test22 " , strPath, xSection2);
DataSetSingle dsSingle = new DataSetSingle();
dsSingle.tblSingle.AddtblSingleRow( " 1 " , " 111 " );
dsSingle.tblSingle.AddtblSingleRow( " 2 " , " 222 " );
dsSingle.tblSingle.AddtblSingleRow( " 3 " , " 333 " );
dsSingle.tblSingle.AddtblSingleRow( " 4 " , " 444 " );
// subRptClientDoc.DatabaseController.AddDataSource(DataSetConverter.Convert(dsSingle));
// visit child reports and databind
_rptContainerDoc.Subreports[ 0 ].SetDataSource(dsSingle);
dsSingle.tblSingle.AddtblSingleRow( " 1 " , " 111 " );
dsSingle.tblSingle.AddtblSingleRow( " 2 " , " 222 " );
dsSingle.tblSingle.AddtblSingleRow( " 3 " , " 333 " );
dsSingle.tblSingle.AddtblSingleRow( " 4 " , " 444 " );
/// /visit child reports and databind
_rptContainerDoc.Subreports[ 1 ].SetDataSource(dsSingle);