我创建了一个主报告文件。然后我创建了子报告文件。有没有办法将子报表文件的xml代码作为报表源?
答案 0 :(得分:0)
覆盖OnBeforePrint
方法并浏览XtraReportBase.Controls
属性树以查找XRSubreport
。如上所述here,您可以使用DataSet
及其DataSet.ReadXml
方法:
protected override void OnBeforePrint(PrintEventArgs e)
{
base.OnBeforePrint(e);
//Get your xml here
var dataSet = new DataSet();
using (var reader = new StringReader(xml))
dataSet.ReadXml(reader);
SetSubReportXML(this, dataSet);
}
private void SetSubReportXML(XRControl xrControl, DataSet dataSet)
{
foreach (XRControl xrControlChild in xrControl.Controls)
{
var subReport = xrControlChild as XRSubreport;
if (subReport != null)
{
//Set your xml here
subReport.ReportSource.DataSource = dataSet;
subReport.ReportSource.DataMember = this.DataMember;
SetSubReportXML(subReport.ReportSource, dataSet);
}
SetSubReportXML(xrControlChild, dataSet);
}
}