无法选择子报告 - .rdlc - VS 2010

时间:2011-12-20 21:33:30

标签: visual-studio-2010 reporting-services rdlc subreport

我使用VS 2008创建了许多报告。现在从VS 2010开始了解新要求。请注意我使用的是.rdlc报告

  • 我可以将子报表控件添加到报表中,但无法选择可用的报表。没有浏览按钮或下拉列表来选择可用的.rdlc报告。

  • 当我手动输入报告名称时,报告查看器不会显示任何子报告。我在“输出”窗口上看不到任何错误消息。

如何在VS 2010中使用子报表?我错过了什么吗?任何帮助表示赞赏。

我安装了SQL 2005/2008(已安装报表服务),VS 2008,VS 2010安装在同一台PC上。

1 个答案:

答案 0 :(得分:0)

首先从工具箱中选择子报告并放在要显示的位置。请参见下图 enter image description here
现在,右键单击子报表属性,然后键入子报表名称。 enter image description here

现在你必须在.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)));
 }

我认为它会对你有用。谢谢。