Hi,
There is GridView with some columns and want to display total of one of the column which is having data of type System.Double. I had look at the same and tried to implement the same but it didn't work and end-up with following exception.
Code
<telerik:GridViewDataColumn DataMemberBinding="{Binding TravelRate, StringFormat=c}"
UniqueName="TravelRate"
Header="Travel Rate"
MinWidth="100">
<telerik:GridViewDataColumn.AggregateFunctions>
<telerik:SumFunction Caption="Sum: "
ResultFormatString="{}{0:c}"
SourceField="UnitPrice" />
</telerik:GridViewDataColumn.AggregateFunctions>
</telerik:GridViewDataColumn>
Exception
No generic method 'Sum' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.
I also had a look at another post where it's mentioned create custom aggregation function. I tried it but didn't get any success.
Code
public class SumFunction : EnumerableSelectorAggregateFunction
{
protected override string AggregateMethodName
{
get { return "Sum"; }
}
protected override Type ExtensionMethodsType
{
get
{
return typeof(Amounts);
}
}
}
public static class Amounts
{
public static Double Sum<T>(IEnumerable<T> source, Func<T, Double> selector)
{
return source.Select(selector).Aggregate(Double.Parse("0"), (t1, t2) => t1 + t2);
}
}
Can please some one help me with this?
Thanks.
There is GridView with some columns and want to display total of one of the column which is having data of type System.Double. I had look at the same and tried to implement the same but it didn't work and end-up with following exception.
Code
<telerik:GridViewDataColumn DataMemberBinding="{Binding TravelRate, StringFormat=c}"
UniqueName="TravelRate"
Header="Travel Rate"
MinWidth="100">
<telerik:GridViewDataColumn.AggregateFunctions>
<telerik:SumFunction Caption="Sum: "
ResultFormatString="{}{0:c}"
SourceField="UnitPrice" />
</telerik:GridViewDataColumn.AggregateFunctions>
</telerik:GridViewDataColumn>
Exception
No generic method 'Sum' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.
I also had a look at another post where it's mentioned create custom aggregation function. I tried it but didn't get any success.
Code
public class SumFunction : EnumerableSelectorAggregateFunction
{
protected override string AggregateMethodName
{
get { return "Sum"; }
}
protected override Type ExtensionMethodsType
{
get
{
return typeof(Amounts);
}
}
}
public static class Amounts
{
public static Double Sum<T>(IEnumerable<T> source, Func<T, Double> selector)
{
return source.Select(selector).Aggregate(Double.Parse("0"), (t1, t2) => t1 + t2);
}
}
Can please some one help me with this?
Thanks.