Gridview平均值问题
GridView里有一列数据如下
123.23
26.35
58.42
0.00
23.00
0.00
现在要求平均值,也就是把(123.23+26.35+58.42+23.00)/4,而零不做计算.请各位写出具体代码,别讲思路!!谢谢
e.Row.Cells[15].Text = ((double)(sum5 / GridView1.Rows.Count)).ToString("f");
e.Row.Cells[15].ForeColor = System.Drawing.Color.Red;
e.Row.Cells[16].Text = ((double)(sum6 / GridView1.Rows.Count)).ToString("f");
e.Row.Cells[16].ForeColor = System.Drawing.Color.Red;
上面的代码把0也算进去了.该怎么改?
[解决办法]
主的gridview源是什么 DataTable
[解决办法]
- HTML code
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID" DataSourceID="SqlDataSource1" onprerender="GridView1_PreRender" ShowFooter="True"> <Columns> <asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False" ReadOnly="True" /> <asp:BoundField DataField="ProductName" HeaderText="ProductName" /> <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" /> </Columns></asp:GridView><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=.;Initial Catalog=Northwind;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="select * from products"></asp:SqlDataSource>