protected void gridSettlement_RowDataBound(object sender, GridViewRowEventArgs e) { if (dtSettlement != null && dtSettlement.Rows.Count > 0) { decimal sum = 0; for (int i = 0; i < dtSettlement.Rows.Count; i++) { sum+= Convert.ToDecimal(dtSettlement.Rows[i].ItemArray[dtSettlement.Columns.IndexOf("Money")]); } // 合计 if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[0].Text = "合计"; e.Row.Cells[4].Text = sum.ToString(); } } } OnRowDataBound="gridSettlement_RowDataBound"