datagrid 在页脚统计

private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        
{            
            
if ( e.Item.ItemIndex >= 0 )
            
{
                
if ( e.Item.Cells[1].Text.ToString().Trim() != " " ) //如果数据不为空
                {
                    countnum 
+= double.Parse(e.Item.Cells[1].Text);//统计求和
                }

                
if ( e.Item.Cells[2].Text.ToString().Trim() != " " ) //如果数据不为空
                {
                    countsize 
+= double.Parse(e.Item.Cells[2].Text.TrimEnd('M'));//统计求和
                }

            }


            
if(e.Item.ItemType==ListItemType.Footer)
            
{
                e.Item.Cells[
0].Text = "合计";
                e.Item.Cells[
1].Text = countnum.ToString();
                e.Item.Cells[
2].Text = countsize.ToString()+"M";
            }

        }
原文地址:https://www.cnblogs.com/lidune/p/659639.html