This is a migrated thread and some comments may be shown as answers.

Decimal Count Totals In Footer

7 Answers 241 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shawn
Top achievements
Rank 1
Shawn asked on 25 Feb 2009, 05:42 PM
I am having problems displaying totals of my decimal columns (sums of columns from SQL Query). I am not certain how it should be done and the error I am getting is: 

Input string was not in a correct format.


If (TypeOf e.Item Is GridDataItem) Then 
            Dim dataItem As GridDataItem = CType(e.Item, GridDataItem) 
 
            Dim fieldValue As Integer = Integer.Parse(dataItem("Total Leads").Text) 
            Leadtotal = (Leadtotal + fieldValue) 
 
            Dim fieldValue2 As Integer = Integer.Parse(dataItem("Credit Count").Text) 
            CreditTotal = (CreditTotal + fieldValue2) 
 
            Dim fieldValue3 As Integer = Integer.Parse(dataItem("Our Cost").Text) 
            OurCostTotal = (OurCostTotal + fieldValue3) 
 
            Dim fieldValue4 As Integer = Integer.Parse(dataItem("Resale Amount").Text) 
            ResaleTotal = (ResaleTotal + fieldValue4) 
 
 
        End If 
        If (TypeOf e.Item Is GridFooterItem) Then 
            Dim footerItem As GridFooterItem = CType(e.Item, GridFooterItem) 
            footerItem("Total Leads").Text = Leadtotal.ToString() 
            footerItem("Credit Count").Text = CreditTotal.ToString() 
            footerItem("Our Cost").Text = OurCostTotal.ToString() 
            footerItem("Resale Amount").Text = ResaleTotal.ToString() 
        End If 

The first two work fine, probably because they are coming from the database as integers.  But even when I try to change #3 and #4 to decimals I get the same error - like this: 
Dim fieldValue3 As Decimal = Decimal.Parse(dataItem("Our Cost").Text) 
            OurCostTotal = (OurCostTotal + fieldValue3) 
 
            Dim fieldValue4 As Decimal = Decimal.Parse(dataItem("Resale Amount").Text) 
            ResaleTotal = (ResaleTotal + fieldValue4) 

What am I doing wrong?


7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Feb 2009, 04:54 AM
Hi Shwan,

I would suggest to use the Aggregate property of the Grid Column. Set the Aggregate to Sum to display the Total in the column footer.

ASPX:
 
 <telerik:GridBoundColumn Aggregate="Sum" DataField"Cost" HeaderText="Cost UniqueName="Cost">  
</telerik:GridBoundColumn >   

Column Aggregates

Shinu

0
Shawn
Top achievements
Rank 1
answered on 26 Feb 2009, 03:56 PM
That works for decimals, but not the integer columns - why is that?  If I add count to the integer fields I just get the count of rows basically, if I add sum I get an error:

Specified cast is not valid.

<telerik:GridBoundColumn DataField="Total Leads" DataType="System.Int32"  
            HeaderText="Total Leads" ReadOnly="True" SortExpression="Total Leads"  
            UniqueName="Total Leads" Aggregate="Sum"
            <FooterStyle Font-Bold="True" HorizontalAlign="Center" /> 
            <HeaderStyle HorizontalAlign="Center" /> 
            <ItemStyle HorizontalAlign="Center" /> 
        </telerik:GridBoundColumn> 


If I take that out and try to do the integer columns the old way I get sums of ZERO now...  Why would that be?

Dim Leadtotal, CreditTotal As Integer 
 
 
        If (TypeOf e.Item Is GridDataItem) Then 
            Dim dataItem As GridDataItem = CType(e.Item, GridDataItem) 
 
            Dim fieldValue As Integer = Integer.Parse(dataItem("Total Leads").Text) 
            Leadtotal = (Leadtotal + fieldValue) 
 
            Dim fieldValue2 As Integer = Integer.Parse(dataItem("Credit Count").Text) 
            CreditTotal = (CreditTotal + fieldValue2) 
 
        End If 
 
        If (TypeOf e.Item Is GridFooterItem) Then 
            Dim footerItem As GridFooterItem = CType(e.Item, GridFooterItem) 
            footerItem("dealer_name").Text = "Totals > > > > >" 
            footerItem("Total Leads").Text = Leadtotal.ToString() 
            footerItem("Credit Count").Text = CreditTotal.ToString() 
        End If 

0
Shawn
Top achievements
Rank 1
answered on 27 Feb 2009, 07:10 PM
Ok, I dont get this...

SUM works fine on all of my decimal columns, but NOT on my integer columns.  I can use count, but count is not what I want.

This WORKS:
<telerik:GridBoundColumn DataField="Our Cost" DataFormatString="{0:c}"  
            DataType="System.Decimal" HeaderText="Our Cost" ReadOnly="True"  
            SortExpression="Our Cost" UniqueName="Our Cost" Aggregate="Sum"
            <FooterStyle Font-Bold="True" /> 
        </telerik:GridBoundColumn> 



AND This WORKS:
<telerik:GridBoundColumn DataField="Credit Count" DataType="System.Int32"  
            HeaderText="Credit Count" ReadOnly="True" SortExpression="Credit Count"  
            UniqueName="Credit Count" Aggregate="Count"
            <FooterStyle HorizontalAlign="Center" Font-Bold="true" /> 
            <HeaderStyle HorizontalAlign="Center" /> 
            <ItemStyle HorizontalAlign="Center" /> 
        </telerik:GridBoundColumn> 

BUT THIS DOES NOT!
<telerik:GridBoundColumn DataField="Credit Count" DataType="System.Int32"  
            HeaderText="Credit Count" ReadOnly="True" SortExpression="Credit Count"  
            UniqueName="Credit Count" Aggregate="Sum"
            <FooterStyle HorizontalAlign="Center" Font-Bold="true" /> 
            <HeaderStyle HorizontalAlign="Center" /> 
            <ItemStyle HorizontalAlign="Center" /> 
        </telerik:GridBoundColumn> 



I get "Specified Cast Is Not Valid" whether I have EnableLinqExpressions set to true or false, doesn't matter...

[InvalidCastException: Specified cast is not valid.]
   System.Linq.<CastIterator>d__aa`1.MoveNext() +131
   System.Linq.Enumerable.Sum(IEnumerable`1 source) +95
   lambda_method(ExecutionScope ) +126
   System.Linq.EnumerableExecutor`1.Execute() +108
   System.Linq.EnumerableQuery`1.System.Linq.IQueryProvider.Execute(Expression expression) +68
   System.Linq.Queryable.Sum(IQueryable`1 source) +163
   Telerik.Web.UI.GridBoundColumn.GetAggregateByType(IQueryable queryable, String fieldName, GridAggregateFunction func) +231

0
Sebastian
Telerik team
answered on 02 Mar 2009, 07:34 AM
Hi Shawn,

Can you check whether setting the EnableLinqExpressions property of the grid to false addresses the error you described? You may also check if stripping the space from the DataField of the column (and from the column name in the source column respectively) makes a difference.

Kind regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Sasa
Top achievements
Rank 1
answered on 18 Mar 2009, 08:24 AM
I have excatly the same problem.

Aggregate sum does not work with my int data but count work just fine with same data.

<

telerik:GridBoundColumn DataField="StuffCount" HeaderText="StuffCount" UniqueName="StuffCount" Aggregate="Sum">

 

 

<FooterStyle HorizontalAlign="Right" />

 

 

<HeaderStyle HorizontalAlign="Center" />

 

 

<ItemStyle HorizontalAlign="Right" />

 

 

</telerik:GridBoundColumn>

 



Is there some solution for this problem?
0
Accepted
Sebastian
Telerik team
answered on 18 Mar 2009, 11:05 AM
Hi Sasa,

Can you confirm that the data type of the source column (presented in the grid with the StuffCount GridBoundColumn) is integer? Thus all aggregates should return expected results for this column based on the integer type. Additionally, set the EnableLinqExpressions property to false to see whether this helps.

Greetings,
Sebastian
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Sasa
Top achievements
Rank 1
answered on 18 Mar 2009, 11:29 AM
Hi, 
yes its definitely integer. 

Finally, solutions is  setting EnableLinqExpressions to false. 

Now is everything ok.

Thanks!
Tags
Grid
Asked by
Shawn
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Shawn
Top achievements
Rank 1
Sebastian
Telerik team
Sasa
Top achievements
Rank 1
Share this question
or