水晶报表子报表
主要分两步:
一,添加报表文件
1)添加主报表数据集treatmentCharge.xsd: 画红线处表示名字在后面中要用到的地方,因为有些地方需要名字一致
2)添加子报表数据集treatmentChargeSub.xsd
3)添加主报表 治疗费用单.rdlc,同时添加数据集
4)在主报表文件中拖入子报表控件,然后单机子报表控件右键,添加子报表名字,同时添加参数
5)添加子报表治疗费用单子报表.rdlc,同时添加数据集,注意名字要一致
6)给子报表治疗费用单子报表.rdlc添加参数,参数跟我们之前在主报表的子报表控件参数要一致
二,后台绑定数据源
主要代码:
DataSet ds = commonws.GetDsOnlySql(strSql);
if(ds.Tables.Count>1)
Report_sub = ds.Tables[1];
//子报表
ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
this.ReportViewer1.LocalReport.ReportPath = Report_Path;
this.ReportViewer1.LocalReport.DataSources.Clear();
this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("bpis_patient_info", ds.Tables[0]));
ReportParameter rp_title = new ReportParameter("report_title",cc.Hospital_Name + Report_Title);
ReportParameter rp_date = new ReportParameter("report_date", Report_Date);
this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp_title,rp_date });
this.ReportViewer1.LocalReport.Refresh();
/// <summary>
/// 子报表
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
e.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("DTSub", Report_sub));
}
效果: