我正在尝试使子报告正常工作。我正在使用 VS 2017。在将我的子报告添加到主报告时,我收到一条错误消息,例如“子报告的数据检索失败,'Subreport1',位于....”。这是我的代码:
public override int RunReport(ref ReportViewer rvNextgenReport)
{
DateTime dt = Convert.ToDateTime(ReportCriteria.DeliveryDate, CultureInfo.InvariantCulture);
string FormattedDeliveryDate = BasePage.GetUSFormattedDate(dt, this.REPORT_BS_DATE_FORMAT);
string FormattedShortDeliveryDate = BasePage.GetUSFormattedDate(dt, this.REPORT_SHORT_DATE_FORMAT);
string GenerationTime = BasePage.GetUSFormattedDate(DateTime.Now, this.REPORT_GEN_DATE_FORMAT);
string firstRouteId;
int find = ReportCriteria.RouteId.ToString().IndexOf(',');
if (find > 0) firstRouteId = ReportCriteria.RouteId.ToString().Substring(0, find);
else
firstRouteId = ReportCriteria.RouteId;
// set the report's parameters
reportParam = new ReportParameter[] {
new ReportParameter("Branch", ReportCriteria.BranchName),
new ReportParameter("DeliveryDate", ReportCriteria.DeliveryDate),
new ReportParameter("IncludeRouteNotesAfterDI", ReportCriteria.includeRouteNotesAfterDI?"1":"0"),
new ReportParameter("FormattedDeliveryDate", FormattedDeliveryDate),
new ReportParameter("FormattedShortDeliveryDate", FormattedShortDeliveryDate),
};
rvNextgenReport.LocalReport.ReportPath = "RouteCardNewSub.rdlc";
rvNextgenReport.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
return runReport(ref rvNextgenReport);
}
public void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
LocalReport lr = (LocalReport)sender;
e.DataSources.Clear();
ReportDataSource rds;
if (e.ReportPath.Contains("sureportsNewSub"))
{
string routeId = e.Parameters["RouteId"].Values[0];
for (int index = 1; index < lr.DataSources.Count; index++)
{
DataTable dt = (DataTable)lr.DataSources[index].Value;
DataView dv = new DataView(dt);
dv.RowFilter = string.Format("RouteId={0}", routeId);
rds = new ReportDataSource(string.Format("RouteCardNew_DataTable{0}", index + 1), dv.ToTable());
e.DataSources.Add(rds);
}
}
}
请注意,我不会在 e 中获得报告路径。LocalReport_SubreportProcessing 中的 Reportspath,我认为这可能会导致这个问题。所以有人请解释为什么这个对象没有得到报告路径信息。