Sorting on a related entity field

2 posts, 0 answers
  1. Greg
    Greg avatar
    1 posts
    Member since:
    Feb 2015

    Posted 25 Oct 2017 Link to this post

    I've got a grid that I need to sort by a column that refers to a related entity. I need to figure out the syntax to do this.

     

    Details:

    <telerik:GridTemplateColumn UniqueName="AGNUM" DataField="AGNUM" HeaderText="Agent" AllowSorting="True" SortExpression="PAgents.AGNAME">
        <EditItemTemplate>
            <telerik:RadComboBox ID="rcb_Agent_Edit" DataSourceID="Entity_Agents_Active"
                AppendDataBoundItems="true" DropDownWidth="400px"
                SelectedValue='<%# Bind("AGNUM") %>' runat="server" DataValueField="AGNUM" DataTextField="AGNAME">
                <Items>
                    <telerik:RadComboBoxItem Text="" Value="99999" />
                </Items>
            </telerik:RadComboBox>
        </EditItemTemplate>
        <ItemTemplate>
            <%# DataBinder.Eval(Container.DataItem, "PAgents.AGNAME") %> <-- Same string works fine here, though.
        </ItemTemplate>
    </telerik:GridTemplateColumn>

    The above throws an argument exception: Input string was not in a correct format.Couldn't store in PAgents.AGNAME Column. Expected type is Int32.

    The grid is bound to an entity data source (defined below)

    The two relevant data sources:

    <asp:EntityDataSource ID="Entity_AgLicensing" runat="server" ConnectionString="name=dev_SuretyDBEntities" ContextTypeName="BSGSuretyRewrite.Entities.DataAccess.LinqToEntities.dev_SuretyDBEntities"
        DefaultContainerName="dev_SuretyDBEntities" EnableFlattening="false" EntitySetName="AgLicense" Include="AgLicenseStatus,PAgents" EnableDelete="true" EnableInsert="true" EnableUpdate="true"
        Where="it.[PNUMBER]=@PNUMBER && it.[AGNUM] IS NOT NULL"
        OnInserting="Entity_AgLicensing_Inserting" OnDeleted="Entity_AgLicensing_Deleted" OnUpdating="Entity_AgLicensing_Updating">
        <WhereParameters>
            <asp:ControlParameter ControlID="hfPnumber" Name="PNUMBER" PropertyName="Value" DbType="Int32" />
        </WhereParameters>
    </asp:EntityDataSource>
    <asp:EntityDataSource ID="Entity_AgLicensing_Agency" runat="server" ConnectionString="name=dev_SuretyDBEntities" ContextTypeName="BSGSuretyRewrite.Entities.DataAccess.LinqToEntities.dev_SuretyDBEntities"
        DefaultContainerName="dev_SuretyDBEntities" EnableFlattening="false" EntitySetName="AgLicense" Include="AgLicenseStatus" EnableDelete="true" EnableInsert="true" EnableUpdate="true"
        Where="it.[PNUMBER]=@PNUMBER && it.[AGNUM] IS NULL" OnInserting="Entity_AgLicensing_Agency_Inserting" OnDeleted="Entity_AgLicensing_Agency_Deleted">
        <WhereParameters>
            <asp:ControlParameter ControlID="hfPnumber" Name="PNUMBER" PropertyName="Value" DbType="Int32" />
        </WhereParameters>
    </asp:EntityDataSource>

     

     

     

  2. Eyup
    Admin
    Eyup avatar
    3817 posts

    Posted 31 Oct 2017 Link to this post

    Hello Greg,

    You can try changing the DataField property of the template column to PAgents.AGNUM or adding the following property:
    <telerik:GridTemplateColumn ... DataType="System.Int32">

    If the issue remains, you will need to update the value manually in the code-behind:
    https://www.telerik.com/forums/how-to-have-dropdownlist-and-textbox-inside-a-radgrid#A9aPQyI5vE-ENWi8clmy6Q

    I hope this will prove helpful.

    Regards,
    Eyup
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top