我有以下代码应该将一些数据绑定到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>();
}