Sort Child Items in Parent Widget Template
I have the following code listing Child Items within a Parent Widget Template.
<sf:DynamicDetailContainer ID=
"detailContainer"
runat=
"server"
>
<LayoutTemplate>
<asp:Repeater runat=
"server"
DataSource=
'<%# Eval("ChildItems") %>'
>
</asp:Repeater>
</LayoutTemplate>
</sf:DynamicDetailContainer>
I would now like to order the Child Items by a custom property, i.e. SortOrder, with something like the following which calls a helper function (see below)
<sf:DynamicDetailContainer ID=
"detailContainer"
runat=
"server"
>
<LayoutTemplate>
<asp:Repeater runat=
"server"
DataSource=
'<%# Helpers.SortOrder(Eval("ChildItems")) %>'
>
</asp:Repeater>
</LayoutTemplate>
</sf:DynamicDetailContainer>
Using the helper function below, I keep getting the following error " Database mapped field uses different type 'System.Nullable' "
public
static
IQueryable<DynamicContent> SortOrder(
object
dynamicContent)
var collection = (IQueryable<DynamicContent>) dynamicContent;
return
collection
.OrderBy(x => x.GetValue<
int
?>(
"SortOrder"
));
Am I going along the right lines?
Hello Sean,
In order to get the value of your custom field of type Number, please use decimal instead of int.
public
static
IQueryable<DynamicContent> SortOrder(
object
dynamicContent)
var collection = (IQueryable<DynamicContent>) dynamicContent;
return
collection
.OrderBy(x => x.GetValue<
decimal
?>(
"SortOrder"
));