Reportviewer不显示来自对象的数据

时间:2014-05-15 06:49:05

标签: c# asp.net entity-framework visual-studio-2013 reportviewer

我已经阅读了关于这个主题的几个问题和答案,这似乎是一个相当常见的话题,但到目前为止还没有人能够帮助我。

我正在使用Visual Studio 2013和实体框架,并尝试从对象创建本地报表并将其显示在reportviewer中。

当我运行它时,报告标题显示但没有数据,尽管调用了我的GetConstraints()方法并且运行没有问题。

数据模型保持相当简单:

public class ConstraintDataModel
{
    public string name { get; set; }
    public int interval { get; set; }
    public string complianceEntity { get; set; }
    public string inspectionEntity { get; set; }
    public string nominalValue { get; set; }
    public int taskID { get; set; }
    public string installations { get; set; }
    public int groupTask { get; set; }
    public string lastInspectionDate { get; set; }
    public string nextInspectionDate { get; set; }
    public int missed { get; set; }
    public string rating { get; set; }
}

返回它的方法一样:

public static List<ConstraintDataModel> GetConstraints()
    {
        List<ConstraintDataModel> constraintList = new List<ConstraintDataModel>();
        List<ICMConstraint> constraints = (List<ICMConstraint>)ctx.ICMConstraints.Where(cust => cust.CustomerID.Equals(1001)).ToList();

        foreach (ICMConstraint constraint in constraints)
        {
            ConstraintDataModel constraintsModel = new ConstraintDataModel();
            constraintsModel.taskID = constraint.ConstraintID;
            constraintsModel.name = constraint.Name;
            constraintsModel.complianceEntity = GetEntityName(constraint.ComplianceEntityID);
            constraintsModel.inspectionEntity = GetEntityName(constraint.InspectionEntityID);
            constraintsModel.installations = GetInstallations(constraint.ConstraintID);
            constraintsModel.interval = constraint.Interval;
            constraintsModel.nextInspectionDate = constraint.NextInspectionDate.ToShortDateString();
            constraintsModel.missed = constraint.MissedInspections;
            constraintsModel.nominalValue = constraint.NominalValue;
            constraintsModel.rating = GetConstraintRating(constraint.ConstraintID);

        }

        return constraintList;
    }

我已经遵循了一些教程,并没有偏离它们。我也尝试在Page_Load上明确绑定数据,但这没有帮助。

我不确定要发布的其他代码,所以如果还有其他需要说的话。

1 个答案:

答案 0 :(得分:1)

您不需要将对象添加到您要返回的列表中:

}
return constraintList;

到此:

    constraintList.Add(constraintsModel);
}
return constraintList;