c#.net windows application -code用于添加多个子报表(vs2010)
问题描述:
嗨.....
i使用reportviewer创建了报告。还添加了单个子报告....我需要在reportviewer上添加多个子报告的代码.me提供我的代码..and ..pls帮我做这个
hi....
i had create report using reportviewer.and also had done adding single subreport....i need code for adding multiple subreports on reportviewer .me provide my code ..and ..pls help me for do this
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt = c.table("select * from staff");
// Load Main Report
reportViewer1.LocalReport.DataSources.Clear();
ReportDataSource rptSource = new ReportDataSource("DataSet1", dt);
reportViewer1.LocalReport.ReportPath = Application.StartupPath + @"\check.rdlc";
reportViewer1.LocalReport.DataSources.Add(rptSource);
// Load Sub Report
this.reportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
// Show Report
reportViewer1.RefreshReport();
}
void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
// populate DataTable only in this sample. In real situation, you can use whatever you want to get the data.
DataTable dt = new DataTable();
dt = c.table("select * from stud");
// Add our DataTable to SubReport
ReportDataSource subRptSource = new ReportDataSource("DataSet1", dt);
e.DataSources.Add(subRptSource);
}
答
为主报表的每个子报表触发子报表处理事件。
目前已处理的子报表数据在SubreportProcessingEventArgs中传递。这将为您提供所需的所有信息。
SubreportProcessing event is triggered for every subreport of your main report.
Currently processed subreport data is passed in SubreportProcessingEventArgs. That gives you all informations what you need.
void LocalReport_SubreportProcessing(object sender, Microsoft.Reporting.WinForms.SubreportProcessingEventArgs e)
{
// Args contains information about currently processed subreport
//e.ReportPath -> Gives you path for your subreport
//e.Parameters -> Parameters of your subreport
//e.DataSourceNames -> List of names of data sources you use in subreport
//e.DataSources -> Returns datasources in your subreport
}
这里有一些链接:
http://www.gotreportviewer.com/ [ ^ ]
http://social.msdn.microsoft.com/Forums/en-US/3cc65613-5880-448e-a2fd-2a403bd2e430/display-multiple-subreports [ ^ ]