答案:创建一个全局变量
Public double Sumdb;
private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType lit=e.Item.ItemType;
if(lit==ListItemType.Footer)
{
TableCell tc1=e.Item.Cells[3];
TableCell tc2=e.Item.Cells[4];
TableCell tc3=e.Item.Cells[5];
TableCell tc4=e.Item.Cells[6];
Label L_xj=new Label();
L_xj.ID="lb_xj";
L_xj.Width=30;
L_xj.Text="合计";
tc1.Controls.Add(L_xj);
Label L_SumData=new Label();
L_SumData.ID="L_SumData";
L_SumData.Width=30;
L_SumData.Text=SumData();
tc2.Controls.Add(L_SumData);
Label L_zj=new Label();
L_zj.ID="lb_zj";
L_zj.Width=30;
L_zj.Text="总合计";
tc1.Controls.Add(L_zj);
Label L_SumPage = new Label();
L_SumPage.ID=”l_sumPage”;
L_SumPage.Width=30;
L_SumPage.Text = Sumdb.ToString();
tc4.Controls.Add(L_SumPage);
}
}private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.AlternatingItem || e.Item.ItemType==ListItemType.Item)
{
if( Convert.ToString( ((DataRowView)e.Item.DataItem)["M_sum"]) != string.Empty)
{
dataSum += Convert.ToDouble(((DataRowView)e.Item.DataItem)["M_sum"]);
}
}
}
//M_sum 为合计的字段名,绑定在DataGrid 的!