XtraReport的報表模板文件是.repx,下面的代碼演示動態加載報表佈局模板。佈局
XtraReport mReport = new XtraReport(); mReport.LoadLayout(Application.StartupPath @"\Reports\" @"rptSO.repx"); //報表模板文件 //取報表數據 DataSet ds = new bllSO().GetReportData(txtNoFrom.Text, txtNoTo.Text, txtDateFrom.DateTime, txtDateTo.DateTime); //查找組件 GroupHeaderBand GroupHeader1 = mReport.FindControl("GroupHeader1", true) as GroupHeaderBand; DetailReportBand DetailReport = mReport.FindControl("DetailReport", true) as DetailReportBand; DetailBand Detail1 = mReport.FindControl("Detail1", true) as DetailBand; XRLabel xrLabel15 = mReport.FindControl("XRLabel15", true) as XRLabel; XRLabel xrLabel23 = mReport.FindControl("XRLabel23", true) as XRLabel; //重要!!!給組(GroupHeader)綁定主鍵字段 //本報表是按業務單號分組 GroupField gf = new GroupField("SONO", XRColumnSortOrder.Ascending); GroupHeader1.GroupFields.Add(gf); //給數據集創建主外鍵關係 DataColumn parentColumn = ds.Tables["tb_SO"].Columns["SONO"]; DataColumn childColumn = ds.Tables["tb_SOs"].Columns["SONO"]; DataRelation R1 = new DataRelation("R1", parentColumn, childColumn); ds.Relations.Add(R1); //綁定主表的數據源 mReport.DataMember = "tb_SO"; mReport.DataSource = ds; //綁定明細表的數據源 DetailReport.DataMember = "R1"; DetailReport.DataSource = ds; //自動綁定明細表XRLabel的數據源 BindingFields(ds, Detail1.Controls); xrLabel15.DataBindings.Add("Text", ds, "R1.Amount");//綁定小計(當前單據的總金額) xrLabel23.DataBindings.Add("Text", ds, "R1.Amount");//綁定總計(全部單據的總金額)