Error: Subreport could not be shown. RDLC using with ASP.NET.
This exception is thrown only in 3 cases:
1. Parameter is not passed to sub report
2. Parameter which is been passed is not been created on sub report
3. Data type of parameter on main report and sub report is not matching up.
C# code which is required to display sub report is mentioned below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
public partial class ReportForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ObjectDataSource obj = new ObjectDataSource();
obj.TypeName = "NorthWindDataSetTableAdapters.CustomersTableAdapter";
obj.SelectMethod = "GetData";
ReportViewer1.LocalReport.ReportPath = "Report.rdlc";
ReportDataSource objSource=new ReportDataSource("DataSet1",obj);
ReportViewer1.LocalReport.DataSources.Add(objSource);
ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(localReport_SubreportProcessing);
ReportViewer1.LocalReport.Refresh();
}
}
void localReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
ObjectDataSource obj = new ObjectDataSource();
obj.TypeName = "NorthWindDataSetTableAdapters.OrdersTableAdapter";
obj.SelectMethod = "GetData";
obj.SelectParameters.Add("CustomerID", e.Parameters["CustomerID"].Values.First());
ReportDataSource objSource = new ReportDataSource("DataSet1", obj);
e.DataSources.Add(objSource);
}
}
To download project click here.
|