0

我正在尝试将外键表数据字段分配给 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" />
                ......
                ......

在此处输入图像描述

我是否以正确的方式做事?

4

1 回答 1

0

既然你喜欢使用Entity Framework. Aspx有一个EntityDatasourceand 用于连接相关表Include,模型构建的每个导航属性都有该属性。实体教程。然后你的绑定看起来像:

 asp:TemplateField...
  asp:Label Text='<%# Eval("tablename.fieldname") %>...
于 2013-03-23T04:47:20.850 回答