0

我正在为一个项目构建一个客户服务模块。我将用户提交的所有投诉存储在数据库中,并获取它们以显示在管理屏幕上。我的两个实体类代表投诉详情和投诉提出者详情如下

    public class Complaint
    {
        #region Fields of the class
        /// <summary>
        /// List of Complaints
        /// </summary>
        private List<Complaint> complaints = new List<Complaint>();

        #endregion

        #region Properties of the class

        public int Id { get; set; }
        public string Type { get; set; }
        public string Description { get; set; }
        public string ActionTaken { get; set; }
        public bool Status { get; set; }
        public DateTime Date { get; set; }
        public CSRInfo CsrId { get; set; }
        public ComplaintRaiserInfo complaintraiser { get; set; }

        #endregion

        #region Methods of the class

        /// <summary>
        /// Gets all the complaints from the List of complaints
        /// </summary>
        /// <returns>Returns the list of the complaints</returns>
        public List<Complaint> GetComplaints()
        {
            return complaints;
        }

        /// <summary>
        /// Adds a complaint to List of Complaints
        /// </summary>
        /// <param name="newComplaint"></param>
        public void AddComplaint(Complaint newComplaint)
        {
            complaints.Add(newComplaint);
        }

        #endregion

    }

    public class ComplaintRaiserInfo
    {
        #region Fields of the class

        public List<int> ComplaintIds = new List<int>();

        #endregion


        #region Properties of the class

        public FlightBooking BookingId { get; set; }
        public string Name { get; set; }
        public string MobileNo { get; set; }
        public string EmailId { get; set; }

        #endregion

        #region Methods of the class
        /// <summary>
        /// Gets all the complaint ids from the List of complaint Ids
        /// </summary>
        /// <returns>Returns the list of the complaint ids</returns>
        public List<int> GetComplaintIds()
        {
            return ComplaintIds;
        }

        /// <summary>
        /// Adds a complaint id to List of Complaint Ids
        /// </summary>
        /// <param name="complaintId"></param>
        public void AddComplaint(int complaintId)
        {
            ComplaintIds.Add(complaintId);
        }
        #endregion

    }

成功从数据库中获取数据,我将其绑定到 ASP.net 网页中的 GridView,如下所示,

    ComplaintManager complaintManager = new ComplaintManager();
    List<Complaint> complaints = new List<Complaint>();
    complaints = complaintManager.GetComplaints();

    GridView1.DataSource = complaints;
    GridView1.DataBind();

我的问题是显示了 Complaint 类的属性,但没有显示 ComplaintRaiserInfo 类的属性。请帮我解决问题。

4

1 回答 1

0

您可以轻松地使用 LINQ 来展平表达式,这通常是绑定到 gridview 的问题:

var complaints = complaintManager.GetComplaints().Select((i) => new { 
  i.ComplaintID,
  i.ComplaintRaiser.ComplaintRaiserID,
  .
  .
});

这很好地绑定到网格。您可以尝试标记中的点表示法,如 ComplainRaiser.ComplaintRaiserID 中的带有 eval 的模板化字段(我自己还没有成功使用 BoundField...)

于 2013-08-02T09:39:09.413 回答