使用Codefluent entitycollection与Infragistics WebHierarchicalDataGrid

时间:2016-10-11 22:10:38

标签: asp.net list infragistics icollection codefluent

我正在寻找一些帮助,将 Codefluent entitycollection与 Infragistics WebHierarchicalDataGrid (v14.2)绑定在一起。为了便于说明,我有两个 Codefluent 实体:Customer和Order;其中一个相关客户有很多相关订单。

在我的ASP页面上,我创建了WebHierarchicalDataGrid,WebHierarchicalDataSource和两个objectDataSource。对于WebHierarchicalDataSource,我创建了两个DataView及其DataRelations。 WebHierarchicalDataGrid的DataMember,Key和DataKeyField都设置正确。

如果objectDataSources SelectMethods设置为CustomerCollection和OrderCollection的 LoadAll 方法,则WebHierarchicalDataGrid将按预期显示 - 即客户行在网格中具有嵌套的订单行,并单击+展开图标显示客户的订单行。

我要做的是根据用户在网页上的文本框中输入的内容,为单个客户显示WebHierarchicalDataGrid。

在后面的代码中,我将Customer的ObjectDataSource的SelectMethod设置为Codefluent模型中定义的方法(LoadByCustomerID),该方法包含一个参数计(CustomerID),我将其设置为文本框中的值。然后我调用Customer的objectDataSources Select方法。这将按预期返回所需的Customer实体。

在返回的Customer实体中,我使用Customer实体中的字段(GUID)中的数据来提供Order的objectDataSources的SelectMethod(LoadOrdersByCustomerGUID)。这也会返回一个或多个相关客户订单的预期OrderCollection。

WebHierarchicalDataGrid中显示的结果仅是父行(所选客户)的结果。客户行中显示+扩展图标,但单击+扩展图标不会显示所选客户的检索订单记录。

如何点击+扩展图标,让WebHierarchicalDataGrid显示客户的相关订单?

       <ig:WebHierarchicalDataGrid ID="hdg_Customer" runat="server" 
       Height="600px" Width="95%" 
       AutoGenerateBands="False" AutoGenerateColumns="False" 
       DataMember="ods_Customer_DefaultView" 
       DataSourceID="hds_Customer" 
       Key="ods_Customer_DefaultView" 
       DataKeyFields="GUID" 
       Enabled="False" >
        <Bands>
            <ig:Band 
                AutoGenerateColumns="False" 
                DataMember="ods_Orders_DefaultView" 
                Key="ods_Orders_DefaultView"
                DataKeyFields="GUID" >
                <Columns>
                    <ig:BoundDataField DataFieldName="GUID" Key="GUID">
                        <Header Text="Order GUID">
                        </Header>
                    </ig:BoundDataField>
                    <ig:BoundDataField DataFieldName="OrderDate" Key="OrderDate">
                        <Header Text="Order Date">
                        </Header>
                    </ig:BoundDataField>
                    <ig:BoundDataField DataFieldName="TotalOrderAmount" Key="TotalOrderAmount">
                        <Header Text="Total Order Amount">
                        </Header>
                    </ig:BoundDataField>                 
                    <ig:BoundDataField DataFieldName="relatedCustomerGUID" Key="relatedCustomerGUID">
                        <Header Text="related Customer GUID">
                        </Header>
                    </ig:BoundDataField>
                </Columns>
            </ig:Band>
        </Bands>
        <Columns>
            <ig:BoundDataField DataFieldName="GUID" Key="GUID">
                <Header Text="Customer GUID">
                </Header>
            </ig:BoundDataField>--%>
            <ig:BoundDataField DataFieldName="CustomerID" Key="CustomerID">
                <Header Text="Customer ID">
                </Header>
            </ig:BoundDataField>
            <ig:BoundDataField DataFieldName="CustomerName" Key="CustomerName">
                <Header Text="Customer Name">
                </Header>
            </ig:BoundDataField>
            <ig:BoundDataField DataFieldName="CustomerState" Key="CustomerState">
                <Header Text="Customer State">
                </Header>
            </ig:BoundDataField>

        </Columns>
    </ig:WebHierarchicalDataGrid>

    <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server"></asp:ScriptManagerProxy>

    <ig:WebHierarchicalDataSource ID="hds_Customer" runat="server">
        <DataViews>
            <ig:DataView ID="ods_Customer_DefaultView" 
                DataMember="DefaultView" 
                DataSourceID="ods_Customer" />
            <ig:DataView ID="ods_Orders_DefaultView" 
                DataMember="DefaultView" 
                DataSourceID="ods_Orders" />
        </DataViews>
        <DataRelations>
            <ig:DataRelation 
                ChildColumns="relatedCustomerGUID" 
                ChildDataViewID="ods_Orders_DefaultView" 
                ParentColumns="GUID" 
                ParentDataViewID="ods_Customer_DefaultView" />
        </DataRelations>
    </ig:WebHierarchicalDataSource>

    <asp:ObjectDataSource ID="ods_Orders" runat="server" 
        DataObjectTypeName="Accounts.Order" 
        OldValuesParameterFormatString="original_{0}" 
        SelectMethod="LoadAll" 
        TypeName="Accounts.OrderCollection"   >
    </asp:ObjectDataSource>

    <asp:ObjectDataSource ID="ods_Customer" runat="server" 
        DataObjectTypeName="Accounts.Customer" 
        OldValuesParameterFormatString="original_{0}" 
        SelectMethod="LoadAll" 
        TypeName="Accounts.CustomerCollection" >
    </asp:ObjectDataSource>
</asp:Content>

选择客户及相关订单 (试着用这个代替):

<asp:ObjectDataSource ID="ods_Orders" runat="server" 
    DataObjectTypeName="Accounts.Order" 
    OldValuesParameterFormatString="original_{0}" 
    SelectMethod="LoadByCustomerGUID" 
    TypeName="Accounts.OrderCollection"   >
    <SelectParameters>
        <asp:Parameter DefaultValue="" Name="CustomerGUID" Type="String" />
    </SelectParameters>
</asp:ObjectDataSource>

<asp:ObjectDataSource ID="ods_Customer" runat="server" 
    DataObjectTypeName="Accounts.Customer" 
    OldValuesParameterFormatString="original_{0}" 
    SelectMethod="LoadBySequence" 
    TypeName="Accounts.CustomerCollection" >
    <SelectParameters>
        <asp:Parameter DefaultValue="0" Name="Sequence" Type="Int32" />
    </SelectParameters>
</asp:ObjectDataSource>

代码背后:

protected void SelectID_Click(object sender, EventArgs e)
{
    Accounts.Customer _customer = default(Accounts.Customer);
    Accounts.CustomerCollection _customers = default(Accounts.CustomerCollection);
    Accounts.OrderCollection _orders = default(Accounts.OrderCollection);
    ods_Customer.SelectParameters("CustomerID").DefaultValue = textbox_CustomerID.Text;
    _customers = ods_Customer.Select();
    _customer = _customers(0);
    ods_Orders.SelectMethod = "LoadByCustomerGUID";
    ods_Orders.SelectParameters("CustomerGUID").DefaultValue = _customer.GUID.ToString;
    _orders = ods_Orders.Select();
}

0 个答案:

没有答案