Domanda

<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" />

Voglio che i dgReports per iniziare a lavorare. Si noti che la casella di testo di posta elettronica funziona bene.

È stato utile?

Soluzione

I effettivamente creato separate origini dati interne, ma ho avuto un altro problema. Non sono riuscito a impostare la clausola Dove ID del genitore dell'Ente.

Si noti che il FormView.DataItem non è accessibile; è di tipo EntityDataSourceWrapper che è una classe amico e inaccessibile.

Così ho creato una funzione di trattare con esso dalla riflessione.

Credo che sia un bug di Microsoft, fino a quando non risolvere il problema, il seguente potrebbe essere utile per chiunque utilizzi i controlli EntityDataSource nidificate.

Qui è:

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

Ora nel codice dietro faccio la seguente:

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

Si noti la gerarchia nel modello:. Account ha molti rapporti

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top