Home » Asp.netRSS

Report Viewer-Report with Subreport

Hi,

I have a reportviewer control (2010) on my form with the following definition.

<rsweb:ReportViewer ID="ReportViewer1" runat="server">
<LocalReport ReportPath="Report1.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="dsApplicants" Name="DataSet1" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:SqlDataSource ID="dsApplicants" runat="server"
SelectCommand="SELECT * FROM [fApplicants]" ConnectionString="<%$ ConnectionStrings:Club CS%>">


Report 1 has a Subreport, how can I set the Datasource for SubReport?

 

4 Answers Found

 

Answer 1

Hi,

Please refer to these:

 

 

<rsweb:ReportViewerID="ReportViewer1"runat="server"Font-Names="Verdana"Font-Size="8pt"Height="800px"Width="100%">

 

<LocalReportReportPath="CustomerInfo.rdlc">

 

<DataSources>

 

 

<rsweb:ReportDataSourceDataSourceId="ObjectDataSource1"Name="CustomersDataSet_Customers"/>

 

 

<rsweb:ReportDataSourceDataSourceId="ObjectDataSource2"Name="OrdersDataSet_Orders"/>

 

</DataSources>

 

</LocalReport>

 

</rsweb:ReportViewer>

 

 

 

<asp:ObjectDataSourceID="ObjectDataSource2"runat="server"SelectMethod="GetData"TypeName="SubReportInLocalReport.OrdersDataSetTableAdapters.OrdersTableAdapter">

 

</asp:ObjectDataSource>

 

 

 

<asp:ObjectDataSourceID="ObjectDataSource1"runat="server"SelectMethod="GetData"TypeName="SubReportInLocalReport.CustomersDataSetTableAdapters.CustomersTableAdapter">

 

 

</asp:ObjectDataSource>

ObjectDataSource1 is the datasource for Main report  ,ObjectDataSource2 is the datasource for subreport.

Challen Fu

 

Answer 2

Thanks Fu,

Actually I am new to ASP.NET a and SSRS.

Now I am getting tis error:

Data retrieval failed for the subreport, 'Subreport1', located at: c:\inetpub\wwwroot\<>\Report2.rdlc. Please check the log files for more information.

Report is workins fine in BI studio but not in report  Viewer.

And How can I view log files?

 

Answer 3

There is some difference between Reporting Service and RDLC local report, we could drag a subreport  into main report  and set this subreport’s name and its parameters, then it will display correctly in the main report, however, we could not just do this in RDLC local report as in reporting service. We could display the subreport by adding an event handler for the SubreportProcessing event of the ReportViewer control. Then, manually set the data source for the report in the event handler process. Just like below code-behind:

private void <FormName>_Load(object sender, EventArgs e)

{

            /*

            Other code is here.

            */

            this.ContactTableAdapter.Fill(this.AdventureWorksDataSet.Contact);

            this.reportViewer1.LocalReport.SubreportProcessing +=

            new SubreportProcessingEventHandler(SubreportProcessingEventHandler);

            this.reportViewer1.RefreshReport();

            /*

            Other code is here.

            */

}

void SubreportProcessingEventHandler(object sender, SubreportProcessingEventArgs e)

{

            e.DataSources.Add(new ReportDataSource("AdventureWorksDataSet_Contact", this.AdventureWorksDataSet.Contact ));

}

This is the same thread; you could click this link to get a reference http://forums.asp.net/t/1479083.aspx

Please feel free to ask.

Best regards,

Challen Fu

 

Answer 4

Thank you very much Fu.

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter