问题
I have one problem in generating Reports in VS2010. I am using RDLC. My task is to generate a report where it should show customer details like Name, Contact number, Email Id etc in the top portion of the report.
In the body section it should show the list reservation details.
My object structure is as follows:
CustomerDetails:
Name
Age
ContactNumber
Email Id
List<ReservationDetails>
ReservationDetails
FromDate
ToDate
Period
Amount
I do not know how to render the List in subreport. It is not dynamic and I got all the details in initial load itself. I split the report into tow section, First (parent) is to show the common details. and Subreport is to show the list of Reservation details.
回答1:
1- Create your Main report that show the customer details as you reauired by passing dataset "Customers"
2- Add a new Report "rptCustomerReservation"
3- Add dataset that returns List by taking a parameter CustomerID
4- In main report , select a cell where you want to add a report, insert -> Sub report
5- Go to Sub Report properties add rptCustomerReservation in name and use report as sub report fields.
6- Select File rptCustomerReservation, in Report data window,right click on Add Prameter, Click Add parameter. Give type ineger. and give name.
7- Go in to main report and right click sub report,go to properties, click parameters tab, give same parameter name and select parameter value from dataset dropdown.
8- Add following code in cs file to register and event to add sub report in page load.
public Ctor()
{
rptViewer.LocalReport.SubreportProcessing += LocalReport_SubreportProcessing);
}
void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
List<CATALOG_ITEM_DETAIL> DTCatalogItemDetail;
if (e.ReportPath == "CatalogItemListItemDetails")
{
DTCatalogItemDetail = report.GetCatalogItemDetail(Convert.ToInt32(e.Parameters[0].Values[0]));
ReportDataSource ds = new ReportDataSource("dsItemDetails", DTCatalogItemDetail);
e.DataSources.Add(ds);
}
}
来源:https://stackoverflow.com/questions/21349546/subreport-in-rdlc-file