0
<asp:FormView DataSourceId="edsAccounts">
    <ItemTemplate>
        <asp:TextBox Text='<%# Eval("Email") %>' />
        <asp:DataGrid ID="dgReports" DataSource='<%# Eval("Reports") %>'>
    </ItemTemplate>
</asp:FormView>
<asp:EntityDataSource ID="edsAccounts" runat="server" ConnectionString="name=Entities" DefaultContainerName="Entities" EntitySetName="Accounts" EntityTypeFilter="Account" Include="Reports" />

dgReports が機能するようにします。電子メール テキスト ボックスは正常に機能することに注意してください。

4

1 に答える 1

0

確かに別の内部データソースを作成しましたが、別の問題が発生しました。Where 句を親のエンティティの ID に設定できませんでした。

FormView.DataItem にアクセスできないことに注意してください。フレンド クラスであり、アクセスできないタイプの EntityDataSourceWrapper です。

そこで、リフレクションで対処する関数を作成しました。

Microsoft のバグだと思います。修正されるまで、以下は、ネストされた EntityDataSource コントロールを使用するすべての人に役立つ可能性があります。

ここにあります:

Module Functions
    Public Function GetEntity(Of TEntity As EntityObject)(ByVal entityDataSourceWrapper As Object) As TEntity
        If entityDataSourceWrapper Is Nothing Then Return Nothing
        Dim type = entityDataSourceWrapper.GetType()
        If Not type.FullName = "System.Web.UI.WebControls.EntityDataSourceWrapper" Then Return Nothing
        Dim wrapper = type.GetProperty("WrappedEntity", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance)
        Return DirectCast(wrapper.GetValue(entityDataSourceWrapper, Nothing), TEntity)
    End Function
End Module

コードビハインドでは、次のことを行います。

Protected Sub fvAccounts_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles fvAccounts.DataBound       
    If fvAccounts.CurrentMode <> FormViewMode.ReadOnly Then Exit Sub
    Dim account As Account = GetEntity(Of Account)(fvAccounts.DataItem)
    If account Is Nothing Then Exit Sub
    Dim edsReports As EntityDataSource = fvAccounts.Row.FindControl("edsReports")
    edsReports.Where = "it.Account.AccountId = " & account.AccountId
    gvReports.DataBind()
End Sub

モデルの階層に注意してください。アカウントには多くのレポートがあります。

于 2009-06-15T07:50:12.273 に答える