首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

Gridview平均值有关问题

2012-02-06 
Gridview平均值问题GridView里有一列数据如下123.2326.3558.420.0023.000.00现在要求平均值,也就是把(123.

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> 

热点排行