<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开始工作。 请注意,电子邮件文本框的作品就好了。

有帮助吗?

解决方案

我确实创造了独立的内部数据源,但我得到了另一个问题。 我无法设置WHERE子句父实体的ID。

注意,FormView.DataItem不可访问;它类型EntityDataSourceWrapper这是一个朋友类和不可访问。

因此,我创建一个功能通过反射来处理它。

我认为这是一个错误微软,直到他们修复它,下面可能是有用的人谁使用嵌套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

请注意模型的层次:客户有很多报道

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top