gridview 求和
NAM_FACT COD_DOLA UNPAID
A CNY 100
B CNY 200
C USD 300
D USD 400
E CNY 500
CNY 800
USD 700
大家好,有问题请大家帮忙了,上面这个示例蓝色部分是已查询后在gridview中实现的,现在我想要加上下面两行求和的部分(注意哦是分组求和的),我想通过sql的方法来实现,不知道怎么做,请大家帮忙了,最好也能给我一个代码的例子,谢谢了!
------解决方案--------------------GridView的Group显示,看这里
http://blog.csdn.net/downmoon/archive/2008/09/14/2832007.aspx
http://www.cnblogs.com/downmoon/archive/2008/08/26/1276538.html
------解决方案--------------------楼主意思是在原来的记录基础上增加 分组求和的记录吧!
------解决方案-------------------- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex >= 0)
{
sum += Convert.ToDouble(e.Row.Cells[2].Text);
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
}
}
或循环gridview,判断值,统计
------解决方案--------------------
------解决方案--------------------给你个代码看看:
C# code
protected void gvService_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (gvService.EditIndex == -1)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string accountname = ((Label)e.Row.Cells[7].FindControl("Label5")).Text;
double money = System.Convert.ToDouble(((Label)e.Row.Cells[5].FindControl("Label3")).Text);
double yjsum = 0.00;
double sjsum = 0.00;
double zssum = 0.00;
if (e.Row.RowIndex == 0)
{
if (accountname == "应收款项")
{
ViewState.Add("YjSumMoney", money);
ViewState.Add("SjSumMoney", 0.00);
ViewState.Add("ZsSumMoney", 0.00);
}
else if (accountname == "实收款项")
{
ViewState.Add("YjSumMoney", 0.00);
ViewState.Add("SjSumMoney", money);
ViewState.Add("ZsSumMoney", 0.00);
}
else
{
ViewState.Add("YjSumMoney", 0.00);
ViewState.Add("SjSumMoney", 0.00);
ViewState.Add("ZsSumMoney", money);
}
}
else
{
yjsum = System.Convert.ToDouble(ViewState["