0

嗨,任何人都可以帮我解决这个问题。我正在使用动态数据并创建了一个自定义页面,该页面显示数据库表中的所有订单。一旦有人选择了一个订单,我希望它显示该订单的所有单个项目。此数据存储在另一个表中,但在同一个数据库中。我在这里发现了一篇非常有用的文章Asp.net Dynamic data multiple relational entity on single page,我认为这几乎给了我我的答案,但我被困在关于实现 IEnumerable 的部分(我正在尝试在这页纸)。我在 IEnumerable 上做了一些阅读,但我真的迷路了。我不确定我是否应该创建一个新课程。任何人都可以帮忙吗?

这是我到目前为止的代码:

HTML 代码:

<h2 class="DDSubHeader">Catering Request Orders</h2>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <div class="DD">
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
                HeaderText="List of validation errors" CssClass="DDValidator" />
            <asp:DynamicValidator runat="server" ID="GridViewValidator" ControlToValidate="GridView1" Display="None" CssClass="DDValidator" />
            <asp:DynamicValidator runat="server" ID="FormViewValidator" ControlToValidate="FormView1" Display="None" CssClass="DDValidator" />

            <asp:QueryableFilterRepeater runat="server" ID="FilterRepeater">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("DisplayName") %>' OnPreRender="Label_PreRender" />
                    <asp:DynamicFilter runat="server" ID="DynamicFilter" OnFilterChanged="DynamicFilter_FilterChanged" /><br />
                </ItemTemplate>
            </asp:QueryableFilterRepeater>
            <br />
            <asp:Button ID="searchButton" runat="server" Text="Search" OnClick="SearchButton_Click" />
        </div>

        <asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource" EnablePersistedSelection="True"
            AutoGenerateSelectButton="True"
            AutoGenerateColumns="False"
            AllowPaging="True" AllowSorting="True" OnDataBound="GridView1_DataBound" 
            OnRowEditing="GridView1_RowEditing" OnSelectedIndexChanging="GridView1_SelectedIndexChanging"
            OnRowDeleted="GridView1_RowDeleted" OnRowUpdated="GridView1_RowUpdated"
            OnRowCreated="GridView1_RowCreated" CssClass="DDGridView"
            RowStyle-CssClass="td" HeaderStyle-CssClass="th" CellPadding="6">

           <Columns>
           <%--<asp:TemplateField>
            <ItemTemplate>
            <asp:DynamicHyperLink ID="DynamicHyperLink1" runat="server" Text="Details" />
            <a id="CategoryRouteID" runat="server" href= '<%# GetRouteInformation() %>'/>

               <%--                 <asp:DynamicHyperLink ID="DynamicHyperLink1" runat="server" Text="Details" />
                        <!-- Create action link to filter items that
                        belong to the same category -->
                         <a ID="CategoryRouteID" runat="server" href='<%# GetRouteInformation() %>'>
                        </a></asp:DynamicHyperLink>

            </ItemTemplate>
           </asp:TemplateField>--%>

            <asp:DynamicField DataField="OrderNo" HeaderText="Order No" />
            <asp:DynamicField DataField="DisplayName" HeaderText="Display name" />
            <asp:DynamicField DataField="EmailAddress" HeaderText="Email address" />
            <asp:DynamicField DataField="DeliveryDate" HeaderText="Delivery date" />
            <asp:DynamicField DataField="Time" HeaderText="Time" />
            <asp:DynamicField DataField="Location" HeaderText="Location" />
            <asp:DynamicField DataField="Site" HeaderText="Site" />
            <asp:DynamicField DataField="OrderProgress" HeaderText="Order progress" />
            <asp:DynamicField DataField="tblCateringOrdersDetailsItems" HeaderText="Item details" />
           </Columns>

            <HeaderStyle CssClass="th" />

            <PagerStyle CssClass="DDFooter" />        
            <RowStyle CssClass="td" />
            <SelectedRowStyle CssClass="DDSelected" />
            <PagerTemplate>
                <asp:GridViewPager ID="GridViewPager1" runat="server" />
            </PagerTemplate>
            <EmptyDataTemplate>
                There are currently no items in this table.
            </EmptyDataTemplate>
            <SortedAscendingHeaderStyle BackColor="#DEDFF0" Font-Bold="True" />
            <SortedDescendingHeaderStyle BackColor="#DEDFF0" Font-Bold="True" />
        </asp:GridView>

        <asp:EntityDataSource ID="GridDataSource" runat="server" EnableDelete="true" EnableUpdate="true" />

        <asp:QueryExtender ID="GridQueryExtender" TargetControlID="GridDataSource" runat="server">
            <asp:DynamicFilterExpression ControlID="FilterRepeater" />
        </asp:QueryExtender>

        <asp:Panel ID="DetailsPanel" runat="server">
            <br /><br />
            <asp:FormView ID="FormView1" runat="server" DataSourceID="DetailsDataSource" RenderOuterTable="false"
                OnPreRender="FormView1_PreRender" OnModeChanging="FormView1_ModeChanging" OnItemUpdated="FormView1_ItemUpdated"
                OnItemInserted="FormView1_ItemInserted" OnItemDeleted="FormView1_ItemDeleted" OnItemCommand="FormView1_ItemCommand">
                <HeaderTemplate>
                    <table id="detailsTable" class="DDDetailsTable" cellpadding="6">
                </HeaderTemplate>
                <ItemTemplate>
                <tr class="td">
                    <td class="DDLightHeader">Order No</td>
                    <td><asp:DynamicControl ID="OrderNo" runat="server" DataField="OrderNo" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">User ID</td>
                    <td><asp:DynamicControl runat="server" DataField="UserID" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Display Name</td>
                    <td><asp:DynamicControl runat="server" DataField="DisplayName" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Email Address</td>
                    <td><asp:DynamicControl ID="EmailAddress" runat="server" DataField="EmailAddress" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Project Code</td>
                    <td><asp:DynamicControl runat="server" DataField="ProjectCode" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Event Description</td>
                    <td><asp:DynamicControl runat="server" DataField="EventDesc" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Delivery Date</td>
                    <td><asp:DynamicControl runat="server" DataField="DeliveryDate" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Date Ordered</td>
                    <td><asp:DynamicControl runat="server" DataField="DateOrdered" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Site</td>
                    <td><asp:DynamicControl runat="server" DataField="Site" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Time</td>
                    <td><asp:DynamicControl runat="server" DataField="Time" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Location</td>
                    <td><asp:DynamicControl runat="server" DataField="Location" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Additional Information</td>
                    <td><asp:DynamicControl runat="server" ID="AdditionalInfo" DataField="AdditionalInfo" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Item Costs</td>
                    <td><asp:DynamicControl runat="server" ID="ItemCosts" DataField="ItemCosts" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">AdditionalCosts</td>
                    <td><asp:DynamicControl runat="server" ID="AdditionalCosts" DataField="AdditionalCosts" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Total Costs</td>
                    <td><asp:DynamicControl runat="server" DataField="TotalCosts" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">More Information Required</td>
                    <td><asp:DynamicControl runat="server" DataField="MoreInformationRequired" UIHint="MultilineText" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Reason Rejected</td>
                    <td><asp:DynamicControl runat="server" DataField="ReasonRejected" UIHint="MultilineText" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Order Progress</td>
                    <td><asp:DynamicControl runat="server" DataField="OrderProgress" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Imported Into Dream</td>
                    <td><asp:DynamicControl runat="server" DataField="ImportedIntoDream" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">View Items</td>
                    <td><asp:DynamicControl  runat="server" DataField="tblCateringOrdersDetailsItems" /></td>
                </tr>
                    <%--<asp:DynamicEntity ID="DynamicEntity1" runat="server" />--%>
                    <tr class="td">
                       <td colspan="2">
                            <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit" Text="Edit" />
                            <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Delete" Text="Delete"
                                OnClientClick='return confirm("Are you sure you want to delete this item?");' />
                           <%-- <asp:LinkButton ID="LinkButton3" runat="server" CommandName="New" Text="New" />--%>
                        </td>
                    </tr>
                </ItemTemplate>
                <EditItemTemplate>
                 <tr class="td">
                    <td class="DDLightHeader">Order No</td>
                    <td><asp:DynamicControl ID="OrderNo" runat="server" DataField="OrderNo" Mode="ReadOnly"/></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">User ID</td>
                    <td><asp:DynamicControl runat="server" DataField="UserID" Mode="ReadOnly"/></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Display Name</td>
                    <td><asp:DynamicControl runat="server" DataField="DisplayName" Mode="ReadOnly" /></td>

                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Email Address</td>
                    <td><asp:DynamicControl runat="server" DataField="EmailAddress" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Project Code</td>
                    <td><asp:DynamicControl runat="server" DataField="ProjectCode" Mode="ReadOnly" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Event Description</td>
                    <td><asp:DynamicControl runat="server" DataField="EventDesc" Mode="ReadOnly" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Delivery Date</td>
                    <td><asp:DynamicControl runat="server" DataField="DeliveryDate" Mode="ReadOnly" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Date Ordered</td>
                    <td><asp:DynamicControl runat="server" DataField="DateOrdered" Mode="ReadOnly" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Site</td>
                    <td><asp:DynamicControl runat="server" DataField="Site" Mode="ReadOnly" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Time</td>
                    <td><asp:DynamicControl runat="server" DataField="Time" Mode="ReadOnly" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Location</td>
                    <td><asp:DynamicControl runat="server" DataField="Location" Mode="ReadOnly" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Additional Information</td>
                    <td><asp:DynamicControl runat="server" DataField="AdditionalInfo" Mode="ReadOnly" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Item Costs</td>
                    <td><asp:DynamicControl runat="server" ID="ItemCosts" DataField="ItemCosts" Mode="Edit" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Additional Costs</td>
                    <td><asp:DynamicControl runat="server" ID="AdditionalCosts" DataField="AdditionalCosts" Mode="Edit" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Total Costs</td>
                    <td><asp:DynamicControl runat="server" ID="TotalCosts" DataField="TotalCosts" Mode="Edit"  /></td>
                    <%--<td><asp:Button runat="server" ID="btnCalculateTotalCosts" Text="Calculate total costs" CommandName="Calculate" /></td>--%>
               <%--   <asp:Button ID="btnUpdateOrder" runat="server" onclick="btnUpdateOrder_Click"
        Text="Update Order" />--%>
                </tr>                    

                <tr class="td">
                    <td class="DDLightHeader">More Information Required</td>
                    <td><asp:DynamicControl runat="server" DataField="MoreInformationRequired" Mode="Edit" UIHint="MultilineText" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Reason Rejected</td>
                    <td><asp:DynamicControl runat="server" DataField="ReasonRejected" Mode="Edit" UIHint="MultilineText" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Order Progress</td>
                    <td><asp:DynamicControl runat="server" DataField="OrderProgress" Mode="Edit" UIHint="OrderProgressDropDown" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">Imported Into Dream</td>
                    <td><asp:DynamicControl runat="server" DataField="ImportedIntoDream" Mode="Edit" /></td>
                </tr>
                <tr class="td">
                    <td class="DDLightHeader">View Items</td>
                    <td><asp:DynamicControl runat="server" DataField="tblCateringOrdersDetailsItems" Mode="Edit" /></td>
                </tr>
                    <%--<asp:DynamicEntity ID="DynamicEntity2" runat="server" Mode="Edit" />--%>
                    <tr class="td">
                        <td colspan="2">
                            <asp:LinkButton ID="LinkButton4" runat="server" CommandName="Update" Text="Update" />
                            <asp:LinkButton ID="LinkButton5" runat="server" CommandName="Cancel" Text="Cancel" CausesValidation="false" />
                        </td>
                    </tr>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:DynamicEntity ID="DynamicEntity3" runat="server" Mode="Insert" />
                    <tr class="td">
                        <td colspan="2">
                            <asp:LinkButton ID="LinkButton6" runat="server" CommandName="Insert" Text="Insert" />
                            <asp:LinkButton ID="LinkButton7" runat="server" CommandName="Cancel" Text="Cancel" CausesValidation="false" />
                        </td>
                    </tr>
                </InsertItemTemplate>
                <FooterTemplate>
                    </table>
                </FooterTemplate>
            </asp:FormView>

            <asp:EntityDataSource ID="DetailsDataSource" runat="server" EnableDelete="true" EnableInsert="true" EnableUpdate="true" />

            <asp:QueryExtender ID="QueryExtender1" TargetControlID="DetailsDataSource" runat="server">
                <asp:ControlFilterExpression ControlID="GridView1" />
            </asp:QueryExtender>
        </asp:Panel>


        <%--code for details items --%>

        <asp:Panel runat="server" ID="PanelItemDetails">
           <asp:GridView ID="GridView2" runat="server" 
                DataSourceID="EntityDataSourceItemDetails" EnablePersistedSelection="True"
                DataKeyNames="OrderNo"
            AutoGenerateSelectButton="True"
            AutoGenerateColumns="False"
            AllowPaging="True" AllowSorting="True" OnDataBound="GridView2_DataBound" 
            OnRowEditing="GridView2_RowEditing" OnSelectedIndexChanging="GridView2_SelectedIndexChanging"
            OnRowDeleted="GridView2_RowDeleted" OnRowUpdated="GridView2_RowUpdated"
            OnRowCreated="GridView2_RowCreated" CssClass="DDGridView"
            RowStyle-CssClass="td" HeaderStyle-CssClass="th" CellPadding="6">

            <Columns>
                <%--<asp:DynamicField DataField="tblCateringItemsDetail" HeaderText="Item" />--%>
                <asp:BoundField DataField="Description" HeaderText="Description" 
                    ReadOnly="True" SortExpression="Description" />
                <asp:BoundField DataField="Quantity" HeaderText="Quantity" ReadOnly="True" 
                    SortExpression="Quantity" />
                <asp:BoundField DataField="TotalUnitCost" HeaderText="TotalUnitCost" 
                    ReadOnly="True" SortExpression="TotalUnitCost" />
                <asp:BoundField DataField="OrderNo" HeaderText="OrderNo" ReadOnly="True" 
                    SortExpression="OrderNo" />
            </Columns>

            <HeaderStyle CssClass="th" />

            <PagerStyle CssClass="DDFooter" />        
            <RowStyle CssClass="td" />
            <SelectedRowStyle CssClass="DDSelected" />
            <PagerTemplate>
                <asp:GridViewPager ID="GridViewPager1" runat="server" />
            </PagerTemplate>
            <EmptyDataTemplate>
                There are currently no items in this table.
            </EmptyDataTemplate>
            <SortedAscendingHeaderStyle BackColor="#DEDFF0" Font-Bold="True" />
            <SortedDescendingHeaderStyle BackColor="#DEDFF0" Font-Bold="True" />
        </asp:GridView>

        <asp:QueryExtender ID="QueryExtender2" TargetControlID="EntityDataSourceItemDetails" runat="server">
                <asp:CustomExpression 
    OnQuerying="OrdersQueryExtender_Querying" />
        </asp:QueryExtender>

            <asp:EntityDataSource ID="EntityDataSourceItemDetails" runat="server" 
                ConnectionString="name=cateringEntities" 
                DefaultContainerName="cateringEntities" EnableFlattening="False" 
                EntitySetName="vCateringOrdersAllDetails" 
                Select="it.[Description], it.[Quantity], it.[TotalUnitCost], it.[OrderNo]"   ORDERBY="it.OrderNo]" >                    
            </asp:EntityDataSource>

        </asp:Panel>

    </ContentTemplate>
</asp:UpdatePanel>

C#代码:

protected void SelectOrder_Selected(object sender, EntityDataSourceSelectedEventArgs e)
    {
        IEnumerable<OrderItems> orderItem = e.Results.Cast<Order>();
        foreach (Order o in orderItem)
        {
            customerId = c.Customer_Id;
        }
    }

     protected void OrderQueryExtender_Querying(object sender, system.Web.UI.WebControls.Expressions.CustomExpressionEventArgs e)
    {
        e.Query = (from a in e.Query.Cast<Order>()
                   where a.OrderNo == orderNo
                   select a);
    }

任何帮助将不胜感激。克莱尔

4

2 回答 2

0

谢谢尼米特的回复。这非常有用。如果它对其他人有帮助,我会在http://www.asp.net/web-forms/tutorials/getting-started-with-ef/the-entity-framework-and-aspnet-getting-找到我正在寻找的东西开始第 4 部分

于 2013-11-12T12:41:19.553 回答
0

我的方法如下

  1. 首先,我显示在网格视图中选择的所有订单的列表。
  2. 当用户选择查看任何订单的详细信息时,我会触发网格视图行命令事件并将订单 ID 作为命令参数传递。
  3. 然后在后面的代码中,我借助步骤 2 中传递的订单 ID 获取订单实体,并与订单实体一起获取订单详细信息并将其显示在第二个网格视图中。
于 2013-11-07T16:06:56.010 回答