putting average of column in footer, I can get the sum

I am able to sum an entire column and put the total in a column, but what if i want to get the average of all the numbers in the column?

    Dim paxaverage As Decimal = 0.0
        Function GetAverage(ByVal hope As Decimal) As Decimal
'this is where i am stuck
            paxaverage += hope / saods.Tables("salesasoftable")Rows.Count
            Return hope
        End Function
        Function Getaverage1() As Decimal
            Return paxaverage
        End Function

Asp side

<asp:TemplateField HeaderText="Remaining PAX">
<ItemTemplate>
 <%#GetAverage(Decimal.Parse(Eval("RemainingPax").ToString())).ToString("N0")%>
</ItemTemplate>
<FooterTemplate>
<%#GetAverage1().ToString("N0")%>
</FooterTemplate>
    <FooterStyle Font-Bold="True" />
</asp:TemplateField>           

Answers


This article discusses a couple of approaches to this problem and gives you some sample code. The one I've used in the past is to have a couple of private fields in the Page code-behind: one for the count and one for the sum. You can then increment these in the GridView's RowDataBound event when the row in question is a data row. When it is a footer row, you compute the average and display it in the right cell.


Need Your Help

Refresh page on load once

php javascript html

this should be so simple but I can't get it to work, all I want to do is to refresh my page immediately once when it is loaded. I don't want to stop caching as much of the data on my site stays the

Allow Cross Domain AJAX in WebKit WebView

objective-c ajax osx cross-domain

I am loading a local webpage in a WebView in my application. Is there a way to enable cross domain AJAX in the webview? There isn't really a point in the security feature if I have control of the c...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.