热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在GridView表VS2010中添加一个GrandTotal页脚-AddaGrandTotalfootertoGridViewtableVS2010

IamtryingtocreateaGrandTotalofallvaluesinaGridViewtablewhichwillbedisplayedinthe

I am trying to create a Grand Total of all values in a GridView table which will be displayed in the footer, I have started by creating the placeholder but not sure how to go about creating the grand total

我试图在GridView表中创建所有值的Grand Total,它将显示在页脚中,我已经开始创建占位符但不知道如何创建总计

        
            
                          
                   

2 个解决方案

#1


1  

Hi in your gridview do this

嗨,在你的gridview做这个


    
        
        
    
    
        
    

Now declare like public

现在宣布像公开一样

Private grdTotal As Decimal = 0

After in the event RowDataBound from your gridview

在您的gridview事件中的RowDataBound之后

If e.Row.RowType = DataControlRowType.DataRow Then
    Dim rowTotal As Decimal =
    Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Amount"))
    grdTotal = grdTotal + rowTotal
End If
If e.Row.RowType = DataControlRowType.Footer Then
    Dim lbl As Label = DirectCast(e.Row.FindControl("lblTotal"), Label)
    lbl.Text = grdTotal.ToString("N2")
End If

#2


1  

If you are adding up just a single column, this should work..

如果你只加一个列,这应该工作..

Code-Behind C#

代码隐藏在C#

decimal totalA = 0;

protected void gvAlexandria_RowDataBound(object sender, GridViewRowEventArgs e)
{
    string totalAmtFinanced = ((Label)gvVehicleTEMP.FooterRow.FindControl("lblTotalAmtFinanced")).Text;

    if (e.Row.RowType == DataControlRowType.DataRow)
    {        
        totalA += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "AmtFinanced"));
    }
    if (e.Row.RowType == DataControlRowType.Footer)
    {
        //Label lblTotal = (Label)e.Row.FindControl("lblTotal");

        if (totalAmtFinanced != null)
        {                   
            totalAmtFinanced = String.Format("{0:c}", totalA);
        }
    }
}

The column in my gridview that I am adding up is called AmtFinanced. This is how I total up a single column. If you have any problems, let me know!

我加入的gridview中的列称为AmtFinanced。这就是我总共单列的方式。如果您有任何问题,请告诉我!


推荐阅读
author-avatar
O依楼观雪O
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有