我用VS 2008创建了许多报告。现在从VS 2010开始,以满足新的需求。请注意我使用的是.rdlc报告
如何在VS 2010中使用子报表?我错过了什么吗?任何帮助表示赞赏。
我安装了SQL 2005/2008(已安装报表服务),VS 2008,VS 2010安装在同一台PC上。
首先从工具箱中选择子报告并放在要显示的位置。请参见下图 现在,右键单击子报表属性,然后键入子报表名称。
现在,您必须在.cs文件中创建一个子报表事件处理程序,您可以从中加载报表:
public Ctor()
{
string path = HttpContext.Current.Server.MapPath("Your Report path");
ReportViewer1.Reset(); //important
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local;
ReportViewer1.LocalReport.SubreportProcessing += Process_Subreport;
LocalReport objReport = ReportViewer1.LocalReport;
objReport.ReportPath = path;
// Add Parameter If you need
List<ReportParameter> parameters = new List<ReportParameter>();
parameters.Add(new ReportParameter("Name", Value));
ReportViewer1.LocalReport.SetParameters(parameters);
ReportViewer1.ShowParameterPrompts = false;
ReportViewer1.ShowPromptAreaButton = false;
ReportViewer1.LocalReport.Refresh();
//Add Datasourdce
ReportDataSource reportDataSource = new ReportDataSource();
reportDataSource.Name = "Datasource Name Used due to report design";
reportDataSource.Value = DataSourceValue;
objReport.DataSources.Add(reportDataSource);
objReport.Refresh();
}
现在创建事件处理程序方法以加载子报表详细信息。
private void Process_Subreport(object sender, SubreportProcessingEventArgs e)
{
//You can get parameter from main report
int paramname = int.Parse(e.Parameters[0].Values[0].ToString());
//You can also add parameter in sub report if you need like main report
//Now add sub report data source
e.DataSources.Add(new ReportDataSource("DataSource Name",DataSourceValue)));
}
我想它会对你有用。谢谢。