当前位置: 代码迷 >> ASP.NET >> Gridview平均值有关问题
  详细解决方案

Gridview平均值有关问题

热度:6400   发布时间:2013-02-25 00:00:00.0
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>
  相关解决方案