どのように私は両親EntityDataSourceナビゲーションプロパティにバインドされた入れ子になったGridViewを作成するのですか?
質問
<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が作業を開始します。 電子メールのテキストボックスがうまく動作することに注意してください。
解決
私は確かに別々の内部データソースを作成したが、私は別の問題です。 私は、親のエンティティのIDにWhere句を設定することができませんでした。
FormView.DataItemにアクセスできないことをお知らせ。それは友人のクラスとアクセスできないタイプEntityDataSourceWrapperのです。
だから私は反射でそれに対処する機能を作成します。
私は、彼らはそれを修正するまで、次のように入れ子になったEntityDataSourceコントロールを使用して誰にも便利かもしれないが、それは、Microsoftのバグだと思います。
ここでは、次のとおりです。
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
モデルで階層を注意:アカウントは、多くのレポートがあります。
。所属していません StackOverflow