Asp.net 在EntityTemplates的列表视图中显示子项
我对asp.net非常陌生,但我发现为现有数据库建立一个脚手架网站非常简单。我已经准备好了 让事情按我所希望的方式进行有点棘手。。我有一个Asp.net 在EntityTemplates的列表视图中显示子项,asp.net,entity-framework-4,Asp.net,Entity Framework 4,我对asp.net非常陌生,但我发现为现有数据库建立一个脚手架网站非常简单。我已经准备好了 让事情按我所希望的方式进行有点棘手。。我有一个Customer表,与ContactMoment表有一对多关系。默认情况下,Customer的详细视图显示查看联系人时刻的链接(默认情况下,该链接在名为Children的字段模板中定义)。我想包括所有联系人时刻的列表视图 我尝试了以下方法: <asp:ListView runat="server" ID="DynamicControl2" DataMem
Customer
表,与ContactMoment
表有一对多关系。默认情况下,Customer
的详细视图显示查看联系人时刻的链接(默认情况下,该链接在名为Children
的字段模板中定义)。我想包括所有联系人时刻的列表视图
我尝试了以下方法:
<asp:ListView runat="server" ID="DynamicControl2" DataMember="ContactMoment" />
其中列出了以下有趣的位。(不幸的是,该项目似乎被放弃了……)
子列表–提供了一种显示子表的方法,与新的编辑和详细信息页面模板配合使用
您需要添加额外的datasource和Listview控件以获得所需的结果
我还没有尝试过这个代码,但它应该可以工作。。。根据实际名称更改实体名称
<asp:EntityDataSource ID="ContactMomentDataSource" runat="server"
ContextTypeName="YourEntities" EnableFlattening="False"
EntitySetName="ContactMoment"
Where="@CustomerID IN (SELECT VALUE Customer.CustomerID FROM it.Customer AS Customer)">
<WhereParameters>
<asp:ControlParameter ControlID="YourDetailView" Type="Int32" Name="CustomerID" PropertyName="SelectedValue" />
</WhereParameters>
</asp:EntityDataSource>
<asp:ListView ID="ContactMomentListView" runat="server"
DataSourceID="ContactMomentDataSource"
AllowSorting="True" AutoGenerateColumns="False"
SelectedRowStyle-BackColor="LightGray"
DataKeyNames="ContactMomentID">
</asp:ListView>
现在,您只需要添加要在Listview的标记中显示的列
希望这有助于……我不确定您的详细信息视图应该填写什么。这一切都将在客户的EntityTemplateUserControl
中实现EntityTemplateUserControl
没有SelectedValue
但是,我不知道您用于显示“Customer”表的控件。默认情况下,它的使用详细信息视图。此控件的id将是“YourDetailView”。您应该使用自定义页面模板而不是EntityTemplate。。。现在可以了,我发现我可以从PageTemplates\Details.aspx
中的FormView
检索当前选择的实体对象ID。为什么建议使用自定义页面模板?我只想更改实体客户的模板。