[英]Cant bind complex property to gridview with entity framework
I have the following code which should bind some data to a gridview but its not working. 我有以下代码,应将一些数据绑定到gridview,但不能正常工作。
THe district manager object has a Brand. 区域经理对象具有品牌。 As you can see in the screenshot the brand is correctly filled in with data.
如您在屏幕截图中所见,品牌已正确填充数据。
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; }
}
Update1 更新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>();
}
This post also speaks about the same / similar problem. 这篇文章也谈到了相同/相似的问题。 Where it "randomly" occurs.
它“随机”发生的地方。 The solution that the questioner found was to use:
发问者发现的解决方案是使用:
<%#Eval("contentsection.Id") %>
The post mentioned has a lot of answers (including an accepted one) that will clarify a lot I presume. 提到的帖子有很多答案(包括一个被接受的答案),这些答案将澄清我的很多假设。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.