2012-04-25 15 views
2

我已經經歷了數百個谷歌結果頁,試圖找到在過去幾天的答案。外鍵表字段不顯示在獨立的動態數據啓用列表視圖

使用獨立動態數據頁面顯示錶,使用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 

回答

1

問題解決了。當所有這些都開始時,我原本得到了錯誤信息:

無法確定一個MetaTable。無法爲數據源'EntityDataSource1'確定MetaTable,並且無法從請求URL中推斷出。確保表映射到反黑組源,或者數據源配置了一個有效的上下文類型和表名,或者該請求是註冊DynamicDataRoute

試圖跟蹤下來導致的部分我擺脫了ASP的:DynamicDataManager標記,並在與替換它的代碼隱藏:

Listview1.EnableDynamicData(GetType(Product)) 
table = theDataSource.GetTable() 

這原來是導致我失望衆所周知的兔子洞......雖然擺脫了元表的錯誤,它無意中造成了我上面寫到的問題。非常感謝:http://daviworld.net/?tag=/DynamicDataManager誰指出這個錯誤信息實際上是由以下原因造成的:

這是由於設計器代碼生成的問題。當您爲GridView控件選擇數據源時,它不會將ContextTypeName屬性添加到EntityDataSourceControl。

一旦我刪除的代碼行以上,並在ASP加回:DynamicDataManager的標記,然後添加一個ContextTypeName =「DAL.NorthwindEntities」到EntitiyDataSource,現在一切工作的人會希望它至。

0

是的,你說的是真的。即時通訊在你卡住的地方。我正在從支柱跑到我的肚子裏放火,但我猜它可能會很快熄滅。

它如何被搞砸,你不能在腳手架機制之外工作,所有你真正在做的就是借用一個動態數據管理器,這樣你就可以在他們的框架和新添加的框架中保持templatised。

我進入這個洞的方式是當我嘗試在同一頁面上顯示多個實體數據。規則的拇指似乎是單個實體,單個頁面。現在,無論什麼即時通訊。再給它幾天,然後我再次打開瓶子..讓有啤酒!