0

I'm very new to asp.net, but I found setting up a scaffolded website for an existing database is super simple. I have it up and running.

Making things work the way I want is a bit more tricky.. I have a Customer table with a one-to-many relationship with the ContactMoment table. By default the detail view of Customer show a link to view the ContactMoments (which is defined in the FieldTemplate called Children by default). What I would like is to include a ListView of all the ContactMoments.

I tried the following:

<asp:ListView runat="server" ID="DynamicControl2" DataMember="ContactMoment" />

This does not work. I probably need to use the DataSourceID, but I have no idea how te retrieve that from the current entity. Could someone point me in the right direction? Thanks :)

Update: I just found Dynamic Data Extensions which lists the following interesting bit. (unfortunately the project seems abandoned..)

  1. ChildrenList – Provides a way to show child tables, works in conjunction with the new Edit and Details page templates.
4

1 に答える 1

1

必要な結果を得るには、追加のデータソースとリストビュー コントロールを追加する必要があります。

このコードは試していませんが、うまくいくはずです...実際の名前に従ってエンティティ名を変更してください..

<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 のマークアップに表示する列を追加するだけです。

お役に立てれば...

于 2012-08-27T18:39:40.657 に答える