【发布时间】:2015-08-14 22:17:02
【问题描述】:
我有三个类(Employee、EmployeeCard 和 Children)像这样实现
public class Employee
{
public Employee()
{
Children = new List<Child>();
}
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
public virtual EmployeeCard EmployeeCard { get; set; }
public virtual IList<Child> Children { get; protected set; }
public virtual void AddChild(Child child)
{
child.Employee = this;
Children.Add(child);
}
public static List<Employee> GetData()
{
List<Employee> empList = new List<Employee>();
for(i=0;i<5;i++)
{
Employee emp = new Employee();
emp.FirstName = "Fname" + i.ToString();
emp.LastName = "Lname" + i.ToString();
emp.EmployeeCard = new EmployeeCard();
emp.EmployeeCard.StartWorkingDate = DateTime.Now.Date.AddDays(-i);
empList.Add(emp);
for(int j=0;j<2;j++)
{
Children child = new Children();
child.FirstName = "ChildFname" + j.ToString();
child.LastName = "ChildLname" + j.ToString();
empList.Children.Add(child);
}
}
return empList;
}
}
public class Child
{
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
public virtual Employee Employee { get; set; }
}
public class EmployeeCard
{
public virtual Employee Employee { get; set; }
public virtual DateTime? StartWorkingDate { get; set; }
}
当我在运行时将员工列表绑定到报告时出现此错误
无法绑定到提供的数据源,因为它不受支持或 未在我们支持的接口中实现。
当我从员工类中删除参考员工卡时,它工作得很好。如何使用员工列表将员工卡的详细信息绑定到报表??
这里是how I created the xtraReports的示例代码
更新 1
这就是我构建员工对象并将它们绑定到报告的方式
XtraReport report = new XtraReport();
List<Employee> ReportDataSource = Employee.GetData();
ReportHeaderBand headerBand = new ReportHeaderBand() {
HeightF = 80
};
report.Bands.Add(headerBand);
headerBand.Controls.Add(new XRLabel() {
Text = "Employee Report",
SizeF = new SizeF(650, 80),
TextAlignment = TextAlignment.BottomCenter,
Font = new Font("Arial", 36)
});
DetailBand detailBandEmployee = new DetailBand();
var detailReportBandEmployee = new DetailReportBand
{
KeepTogether = true,
DataMember ="",
DataSource = ReportDataSource
};
detailReportBandEmployee.Bands.Add(detailBandEmployee);
XRLabel lbFname = new XRLabel() {
LocationF = new PointF(200, 10),
SizeF = new SizeF(440, 50),
TextAlignment = TextAlignment.BottomLeft,
Font = new Font("Arial", 24)
};
detailBandEmployee.Controls.Add(lbFname);
lbFname.DataBindings.Add("Text", null, "FirstName");
XRLabel lbLastName = new XRLabel() {
LocationF = new PointF(200, 60),
SizeF = new SizeF(440, 40),
TextAlignment = TextAlignment.TopLeft,
Font = new Font("Arial", 14, FontStyle.Italic)
};
detailBandEmployee.Controls.Add(lbLastName);
lbLastName.DataBindings.Add("Text", null, "LastName");
DetailBand detailBandEmployeeChild = new DetailBand();
var detailReportBandEmployeeChild = new DetailReportBand
{
KeepTogether = true,
DataMember = "Children",
DataSource = ReportDataSource
};
detailReportBandEmployeeChild.Bands.Add(detailBandEmployeeChild);
XRLabel lbChildFname = new XRLabel()
{
LocationF = new PointF(200, 10),
SizeF = new SizeF(440, 50),
TextAlignment = TextAlignment.BottomLeft,
Font = new Font("Arial", 24)
};
detailBandEmployeeChild.Controls.Add(lbChildFname);
lbChildFname.DataBindings.Add("Text", null, "FirstName");
XRLabel lbChildLastName = new XRLabel()
{
LocationF = new PointF(200, 60),
SizeF = new SizeF(440, 40),
TextAlignment = TextAlignment.TopLeft,
Font = new Font("Arial", 14, FontStyle.Italic)
};
detailBandEmployeeChild.Controls.Add(lbChildLastName);
lbChildLastName.DataBindings.Add("Text", null, "LastName");
DetailBand detailBandEmployeeCard = new DetailBand();
var detailReportBandEmployeeCard = new DetailReportBand
{
KeepTogether = true,
DataMember = "EmployeeCard ",
DataSource = ReportDataSource
};
detailReportBandEmployeeCard.Bands.Add(detailBandEmployeeCard);
XRLabel lbStartDate = new XRLabel()
{
LocationF = new PointF(200, 10),
SizeF = new SizeF(440, 50),
TextAlignment = TextAlignment.BottomLeft,
Font = new Font("Arial", 24)
};
detailBandEmployeeCard.Controls.Add(lbStartDate);
lbStartDate.DataBindings.Add("Text", null, "StartWorkingDate");
detailReportBandEmployee.Bands.Add(detailReportBandEmployeeCard);
detailReportBandEmployee.Bands.Add(detailReportBandEmployeeChild);
report.Bands.Add(detailReportBandEmployee);
【问题讨论】:
-
您能发布一下您是如何进行绑定以及如何构建员工对象的吗?
-
@deramko 查看更新
标签: c# linq devexpress xtrareport