我已經經歷了數百個谷歌結果頁,試圖找到在過去幾天的答案。外鍵表字段不顯示在獨立的動態數據啓用列表視圖
使用獨立動態數據頁面顯示錶,使用EntityDataSource,其中一個字段是子表的外鍵。我希望它顯示子表中的值。我一直在使用NorthWinds數據庫玩一個簡單的案例(見下面的代碼)。如果我將DynamicControl分配給DataField =「Supplier」,它將顯示子表/類名稱(「DAL.Supplier」)。如果我嘗試分配DataField =「Supplier.CompanyName」,那麼「The table'Product'的錯誤沒有名爲'Supplier.CompanyName'的列」。由於我想利用動態數據的編輯功能,因此使用帶有<%#Eval(「Supplier.CompanyName」)%>的模板字段已不存在。
這對於獨立的動態數據頁面來說是不可能的嗎?它完全可以在一個完全腳手架的系統內正常工作。或者我(希望)只是錯過了什麼?謝謝。
Test.aspx文件
<%@ Page Title="" Language="VB" MasterPageFile="~/Master/Site.master" AutoEventWireup="false" CodeFile="Test.aspx.vb" Inherits="Test" %>
<asp:Content ID="Content3" ContentPlaceHolderID="BodyContent" Runat="Server">
<asp:ListView ID="ListView1" runat="server" DataSourceID="theDataSource" DataKeyNames="ProductID">
<ItemTemplate>
<tr>
<td>
<asp:DynamicControl runat="server" DataField="ProductID" Mode="Edit" />
</td>
<td>
<asp:DynamicControl runat="server" DataField="ProductName" Mode="Edit" />
</td>
<td>
<asp:DynamicControl runat="server" DataField="Supplier" Mode="Edit" />
</td>
<td>
<asp:DynamicControl runat="server" DataField="UnitPrice" Mode="Edit" />
</td>
<td>
<asp:DynamicControl runat="server" DataField="Discontinued" Mode="Edit" />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0">
<tr runat="server">
<th runat="server">
ProductID
</th>
<th runat="server">
ProductName
</th>
<th runat="server">
Supplier
</th>
<th runat="server">
UnitPrice
</th>
<th runat="server">
Discontinued
</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server">
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
<asp:EntityDataSource ID="theDataSource" runat="server"
ConnectionString="name=NorthwindEntities"
DefaultContainerName="NorthwindEntities" EnableDelete="True"
EnableFlattening="False" EnableInsert="True" EnableUpdate="True"
Include="Supplier"
EntitySetName="Products">
</asp:EntityDataSource>
</asp:Content>
Test.aspx.vb
Imports System.Web.DynamicData
Imports DAL
Partial Class Test
Inherits System.Web.UI.Page
Protected table As MetaTable
Protected Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
Listview1.EnableDynamicData(GetType(Product))
table = theDataSource.GetTable()
Title = table.DisplayName
End Sub
End Class