Sorting by related entity's property in DataGridView
Posted: Thu Jun 04, 2015 11:15 am
If I have the following cb:AbleGridView (or asp:DataGridView) and asp:ObjectDataSource, is there a way to sort the grid by the Product.Sku property?
Note that setting the Text property of the ItemTemplate to '<%# Eval("Product.Sku") %>' shows the Sku correctly.
However, setting the SortExpression property of the TemplateField to "Product.Sku" like this:
results in an error:
Code: Select all
<cb:AbleGridView ID="SpecialGrid" runat="server" AutoGenerateColumns="False" DataKeyNames="SpecialId" DataSourceID="SpecialDs"
AllowSorting="True" SkinID="PagedList" AllowPaging="True" PageSize="20" PagerSettings-Position="TopAndBottom" EnableViewState="false" Width="100%">
<Columns>
<asp:TemplateField HeaderText="Part #">
<ItemTemplate>
<asp:Label ID="Sku" runat="server" Text='<%# Eval("Product.Sku") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<%-- other fields --%>
</Columns>
</cb:AbleGridView>
<asp:ObjectDataSource ID="SpecialDs" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="LoadAll" TypeName="CommerceBuilder.Products.SpecialDataSource"
DataObjectTypeName="CommerceBuilder.Products.Special" DeleteMethod="Delete" SortParameterName="sortExpression" EnablePaging="true">
</asp:ObjectDataSource>
However, setting the SortExpression property of the TemplateField to "Product.Sku" like this:
Code: Select all
<asp:TemplateField HeaderText="Part #" SortExpression="Product.Sku">
[QueryException: could not resolve property: Product.Sku of: CommerceBuilder.Products.Special]
NHibernate.Persister.Entity.AbstractPropertyMapping.ToColumns(String alias, String propertyName) +372
NHibernate.Persister.Entity.BasicEntityPropertyMapping.ToColumns(String alias, String propertyName) +266
NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetColumnAliasesUsingProjection(ICriteria subcriteria, String propertyName) +374
NHibernate.Criterion.Order.ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery) +380
NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetOrderBy() +235
NHibernate.Loader.Criteria.CriteriaJoinWalker..ctor(IOuterJoinLoadable persister, CriteriaQueryTranslator translator, ISessionFactoryImplementor factory, ICriteria criteria, String rootEntityName, IDictionary`2 enabledFilters) +495
NHibernate.Loader.Criteria.CriteriaLoader..ctor(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, CriteriaImpl rootCriteria, String rootEntityName, IDictionary`2 enabledFilters) +258
NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results) +672
NHibernate.Impl.CriteriaImpl.List(IList results) +63
NHibernate.Impl.CriteriaImpl.List() +79
CommerceBuilder.DomainModel.RepositoryWithTypedId`2.LoadAll(String sortExpression, Int32 maximumRows, Int32 startRowIndex) +188
CommerceBuilder.DomainModel.DataSourceWithTypedId`3.LoadAll(Int32 maximumRows, Int32 startRowIndex, String sortExpression) +93