C# ReportViewer中的子表
我需要在报告查看器(rdlc文件)中显示客户列表(每页一个客户),以及与该客户相关的订单(在客户信息的同一页)和评论。如何插入tablix,以便每个客户都有一个分页符 它应该是这样的: 这就是我希望在报告中添加数据的方式:C# ReportViewer中的子表,c#,reportviewer,C#,Reportviewer,我需要在报告查看器(rdlc文件)中显示客户列表(每页一个客户),以及与该客户相关的订单(在客户信息的同一页)和评论。如何插入tablix,以便每个客户都有一个分页符 它应该是这样的: 这就是我希望在报告中添加数据的方式: List<Customer> customers = db.Customers; LocalReport.DataSources.Add(new ReportDataSource("Customers", customers)) public class C
List<Customer> customers = db.Customers;
LocalReport.DataSources.Add(new ReportDataSource("Customers", customers))
public class Customer
{
public string Name { get; set; }
public string PhoneNumber { get; set; }
public List<Order> Orders { get; set; }
public List<Comment> Comments { get; set; }
}
public class Order
{
public string Product { get; set; }
public int Qty { get; set; }
public decimal Price { get; set; }
}
public class Comment
{
public string Description { get; set; }
}
List customers=db.customers;
LocalReport.DataSources.Add(新的ReportDataSource(“Customers”,Customers))
公共类客户
{
公共字符串名称{get;set;}
公共字符串PhoneNumber{get;set;}
公共列表顺序{get;set;}
公共列表注释{get;set;}
}
公共阶级秩序
{
公共字符串乘积{get;set;}
公共整数数量{get;set;}
公共十进制价格{get;set;}
}
公开课评论
{
公共字符串说明{get;set;}
}
编辑:也许我没有正确地表达。我不知道如何显示每个客户的订单和对列表项目的评论。我需要如何分组?如何将数据集设置为子表(用于订单和注释)以下MSDN页面
指示如果要向表、矩阵或列表中的行组添加分页符,请执行以下步骤:
我最后使用子报表:
LocalReport.SubreportProcessing += Customers_SubreportProcessing;
private void Customers_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
ReportParameterInfo customerId = e.Parameters.FirstOrDefault(c => c.Name == "CustomerId");
if (customerId== null)
return;
Customer customer = _customersList
.FirstOrDefault(c => c.CustomerId == customerId.Values.FirstOrDefault());
if (e.ReportPath == "CustomersOrders") // Name for subreport CustomersOrders.rdlc
{
e.DataSources.Add(new ReportDataSource("Orders", customer.Orders));
}
else if (e.ReportPath == "CustomersComments") // Name for subreport CustomersComments.rdlc
{
e.DataSources.Add(new ReportDataSource("Comments", customer.Comments));
}
}
在报表设计器中,右键单击此项并选择“在此列表之前插入分页符”应有效。在Tablix中添加客户上的行组,在组更改后将行组设置为分页符。