Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
You could display a Subreport in Server report easily; however, you will get error message: Sub report could not be shown if you just follow above article to add a subreport in a local report. This article describes how to add a subreport in a local report.
The sample in this article uses the NorthWind database, the report displays the Customers list and Customer's detailed Order information of every Customer.
•1. Create a web application
•2. Create a Main report using Report Wizard
3 . Create a Sub report using report Wizard
•a. Right-click the project name again to select Report Wizard template, and then type in "OrderInfo"for report name.
4 . Add a parameter CustomerID for Subreport to filter the Subreport's DataSet
5 . Drag a Subreport control into Main report
6. Add a ReportViewer control into your Web Form
7. Add below code to display Subreport in Main report with ReportViewer control
protected void Page_Load(object sender, EventArgs e) { ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SetSubDataSource); this.ReportViewer1.LocalReport.Refresh(); } public void SetSubDataSource(object sender, SubreportProcessingEventArgs e) { e.DataSources.Add(new ReportDataSource("OrdersDataSet__Orders", "ObjectDataSource2")); } |
8. Add a drill-down feature to the main report
Run the project, you will get the report like picture one, which display all customers' information, drill-down the + sign, you will get all the orders' detail information of every customer, as picture two's layout.
Reference
Configuring Subreports and Drillthrough Reports
LocalReport.SubreportProcessing Event
Anonymous
September 13, 2011
The comment has been removed
Anonymous
December 19, 2011
It is a typo, thanks Jean for pointing this out
Anonymous
July 09, 2012
Thank you so much , that's what i want ...
Anonymous
September 16, 2012
Dear Sir,
Im using visual studio 2010, I Generate Main report with subreport.
But i can't able to toogleItem, whenever i click subreport , it is not exapnd..
Pls Help me
With Regards,
Vidhya.C
Anonymous
December 11, 2012
thank you for example code. it very very useful for me
Anonymous
December 18, 2012
Hi Vidhya,
Please follow step 8. Add a drill-down feature to the main report.
Make sure you select the correct Field as ToggleItem
Anonymous
March 14, 2013
How can you do this using Visual Studio 2010?
Anonymous
March 27, 2013
@ Vidhya
for toggle: use the following:
if (!Page.IsPostBack)
{
ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SetSubDataSource);
this.ReportViewer1.LocalReport.Refresh();
}
public void SetSubDataSource(object sender, SubreportProcessingEventArgs e)
{
e.DataSources.Add(new ReportDataSource("ItemSet", "ObjectDataSource2"));
}
Anonymous
April 25, 2013
The comment has been removed
Anonymous
March 17, 2014
thanks for this article but I have error of "Error: Subreport could not be shown."
Anonymous
August 12, 2014
what if i have two subreport like subreport1 and subreport2 in a mainreport ????
i have tried by having two different SubreportProcessingEventHandler but one subreport load succesfully while in subreport2 only columns names are shown without data ???
Thanks !
Anonymous
September 09, 2014
I am getting an error
"A data source instance has not been supplied for the data source NorthwindDataSet_Orders"
Bouth tables Customers and Orders work fine in the Designer
What's wrong?
Anonymous
September 11, 2014
If you have any quesiton, please post it in the following forum:
social.technet.microsoft.com/.../home
Anonymous
April 15, 2015
how to use report containing subreport to generate report from rdl file in application
Anonymous
August 04, 2015
It can do on Reportviewer of windows form ? I want guild how to do?
Anonymous
January 07, 2016
I am using visual studio 2010.I don't make from step 3.Plz helps sir
Anonymous
January 21, 2016
Knowledge is good but explanation is worst. Improve it.
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in