日期:2014-05-20  浏览次数:20549 次

DataGrid显示中对某列的值进行相加,在其下面显示
DataGrid显示中对某列的值进行相加,在其下面显示!

------解决方案--------------------
private void dgMeets_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
...{

if(e.Item.ItemType== ListItemType.Item || e.Item.ItemType== ListItemType.Item)
...{
//某列总和
intTotalNew=0;
int i;
DataTable myTable;
myTable = (DataTable) ((DataSet)this.dgMeets.DataSource).Tables[0];
for(i = 0;i < myTable.Rows.Count;i++)
...{
intTotalNew+=int.Parse(myTable.Rows[i][ "attendnum "].ToString());
}
}
else if (e.Item.ItemType== ListItemType.Footer)
...{
e.Item.Cells[6].Text = "总计: " + intTotalNew.ToString()+ "人 ";
e.Item.Cells[6].Attributes.Add( "Align ", "Right ");
}
}

现成的代码!
------解决方案--------------------
int Total =0;
foreach(DataGridItem dri in DataGrid1)
{
Total+=int.Parse(DataGrid1.Items[dri.ItemIndex].Cells[你的列].ToString());
}