asp.net增加合计行
protected void gvWorkOrder_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow) //检查是否为datarow
{
totalcash += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "cash"));
totalunbalanced += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "unbalanced")); totalsettled += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "settled")); } else if(e.Row .RowType ==DataControlRowType .Footer ) { e.Row.Cells[0].Text = "合计"; e.Row.Cells[1].Text = totalcash.ToString("0.00"); e.Row.Cells[2].Text = totalunbalanced.ToString("0.00"); e.Row.Cells[3].Text = totalsettled.ToString("0.00"); e.Row.Font.Bold = true; }
if (e.Row.RowType == DataControlRowType.DataRow) //检查是否为datarow { //DateTime PlanStart = Convert.ToDateTime(DataBinder.Eval(e.Row.DataItem, "FName")); //取得数据 //if (PlanStart < DateTime.Parse(txtStartDate.Text)) //{ // e.Row.BackColor = System.Drawing.Color.FromName("#FFCCCC"); //颜色突出显示 //} double totalnum=0; double totalMoney=0; DataRowView drvBasicCountInfor = (DataRowView)e.Row.DataItem; double inum = Convert.ToDouble(drvBasicCountInfor[6].ToString());//6是第5列的数字 //生成总计 //totalNumber += iNumber; totalnum += inum; Double imoney = Convert.ToDouble(drvBasicCountInfor[8].ToString());//6是第5列的数字 //生成总计 //totalmoneyNumber += imoneyNumber; totalMoney += imoney; //e.Row.Cells[0].Text = "总计:"; //e.Row.Cells[5].Text = string.Format("{0}", totalnum); e.Row.Cells[6].Text = string.Format("{0:c}", totalMoney); e.Row.Cells[8].Text = string.Format("{0:c}", imoney); }