分配给gridview时找不到外键表数据字段?

时间:2013-03-23 00:51:02

标签: asp.net vb.net gridview

我正在尝试将外键表数据字段分配给gridview。它低于错误。

  

名称为“Dim_Hierarchy.Business_Unit_Name”的字段或属性   未在所选数据源中找到。

代码背后

  Public Function GetInitiativeDataList(ByVal client_Idx As Integer) As List(Of Fact_Initiative)
    Dim fact_Initiative As IList(Of Fact_Initiative)
    Dim SGAEntities As New SGATLEntities()

    fact_Initiative = (From factInitiative In SGAEntities.Fact_Initiative Where factInitiative.Client_Idx = client_Idx).ToList()

    Return fact_Initiative
End Function

ASPX页面

<asp:GridView ID="gvInitiavtives" runat="server" Width="100%" CssClass="Grid" 
      RowStyle-Width="30px" AutoGenerateColumns="false" HeaderStyle-CssClass="GridHeader"   RowStyle-CssClass="GridItem" AlternatingRowStyle-CssClass="GridAltItem">
      <Columns>
         <asp:BoundField DataField="Dim_Hierarchy.Business_Unit_Name" HeaderText="" HeaderStyle-Wrap="false" HeaderStyle-HorizontalAlign="NotSet" />
         <asp:BoundField DataField="Dim_Hierarchy.Business_Unit_Function" HeaderText="" HeaderStyle-Wrap="false" HeaderStyle-HorizontalAlign="NotSet" />
                ......
                ......

enter image description here

我是以正确的方式做的吗?

1 个答案:

答案 0 :(得分:0)

由于您喜欢使用Entity FrameworkAspxEntityDatasource,并且为了挂钩相关表,模型构建的每个导航属性都有Include属性。 Entity Tutorial。然后您的Binding看起来像:

 asp:TemplateField...
  asp:Label Text='<%# Eval("tablename.fieldname") %>...