1

我有以下代码应该将一些数据绑定到gridview,但它不起作用。

区域经理对象有一个品牌。正如您在屏幕截图中看到的,品牌已正确填写了数据。

 private void LoadData()
        {
            List<DealerDistrictManager> listDealerDistrictManager = DistrictManagerBL.GetAllDealersWithDistrictManagers();
            DistrictManagersGrid.DataSource = listDealerDistrictManager;
            DistrictManagersGrid.DataBind();


     <asp:BoundColumn DataField="DistrictManagerId" Visible="False"></asp:BoundColumn> 
        <asp:BoundColumn DataField="Brand.Name" meta:resourcekey="BrandHeader"></asp:BoundColumn>


 public class DealerDistrictManager
    {
        public int DistrictManagerId { get; set; }
        public string Nuteres { get; set; } 
        public string DealerNumber { get; set; }
        public virtual Brand Brand { get; set; }
        public int DistrictNumber { get; set; }
        public string Name { get; set; }
    }

 public class Brand
    {
        public int BrandId { get; set; }
        public string Name { get; set; }
    }

更新1

public List<DealerDistrictManager> GetAllDealersWithDistrictManagers()
    {

            return  (from d in _context.Dealers
                      from m in _context.DistrictManagers
                      where d.Nuteres == m.DealerNuteres
                     select new DealerDistrictManager
                                { 
                                    DistrictManagerId= m.DistrictManagerId,
                                    Nuteres = d.Nuteres,
                                    DealerNumber = d.DealerNumber,
                                    Brand  = m.Brand,
                                    DistrictNumber = m.DistrictNumber,
                                    Name = m.Name

                                 }).ToList<DealerDistrictManager>(); 

    }

在此处输入图像描述

4

1 回答 1

0

这篇文章也谈到了相同/相似的问题。它“随机”发生的地方。提问者找到的解决方案是使用:

<%#Eval("contentsection.Id") %>

提到的帖子有很多答案(包括一个已接受的答案),我认为这些答案会澄清很多。

于 2012-05-30T09:03:27.593 回答