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

列表最后一起加小计或总计 ——小总结

2012-11-22 
列表最后一行加小计或总计 ——小总结1.所有分页的总计protected void dvList_ItemDataBound(object sender,

列表最后一行加小计或总计 ——小总结

1.所有分页的总计

protected void dvList_ItemDataBound(object sender, DataGridItemEventArgs e)
??????? {
??????????? if (e.Item.ItemType == ListItemType.Footer)
??????????? {
??????????????? int c1 = 0;
??????????????? int c2 = 0;
??????????????? int c3 = 0;

//传入查询的sql语句和参数
??????????????? using (SqlDataReader dr = xtDAO.SqlText.ExecuteReader(sSql, pam.ToArray()))
??????????????? {
??????????????????? while (dr.Read())
??????????????????? {

???????//每列累加
??????????????????????? c1 += Convert.ToInt32(dr["byjkxs"]);
??????????????????????? c2 += Convert.ToInt32(dr["bybfhxs"]);
??????????????????????? c3 += Convert.ToInt32(dr["byzgxs"]);
??????????????????? }
??????????????? }

??????????????? // 设置在 DataGrid 中显示的值
??????????????? e.Item.Cells[0].Text = "<font color='red'>总计:</font>";
??????????????? e.Item.Cells[4].Text = c1.ToString();
??????????????? e.Item.Cells[5].Text = c2.ToString();
??????????????? e.Item.Cells[6].Text = c3.ToString();
??????????? }
??????? }

?

这个总计的就是在执行底部的时候执行(ListItemType.Footer)。就只执行一次了

?

2.小计

小计的就是每页中的所有列累加? 所有也可以在行绑定里面 但是是在(if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem))

然后通过e.Item.cell[0]获取值 进行累加 然后 在ListItemType.Footer的时候加进去 也和上面类似!

?

总结:不管是小计还是总计都是要在Footer的时候加上去,区别就是取值不一样,总计的就传查询全部的sql,小计的话,是AlternatingItem的时候累加 放到变量中保存。另外还有一个就是要记得设置list显示底部属性ShowFooter="true"

?

?

热点排行