1.設置gridview裡面的屬性中ShowFooter="True",就是把gridview的頁腳顯示出來 this.gvData.OptionsView.ShowFooter = true; 2.設置要彙總的列,例如彙總"ReceiveMoney"金額列 3.給gridView添加CustomS ...
1.設置gridview裡面的屬性中ShowFooter="True",就是把gridview的頁腳顯示出來
this.gvData.OptionsView.ShowFooter = true;
2.設置要彙總的列,例如彙總"ReceiveMoney"金額列
3.給gridView添加CustomSummaryCalculate事件
private DataTable _dtSummaryTable = null;
string sql="SELECT * FROM Pay_Payable";
string sqlSummary = string.Format(@"SELECT SUM(ReceiveMoney) AS TotalReceiveMoney FROM ({0}) TEMP ", strSql);
sqlList.Add(sqlSummary);
string result = _mTargetService.GetEmployeePagerJson(strSql, deptId, Pager.PageIndex, Pager.PageSize, _gridSortAdv.OrderType, _gridSortAdv.OrderField, out totalRecord);
if (result != "")
{
_dtSummaryTable = JSonHelper.Deserialize<DataTable>(result);
}
/// <summary>
/// 彙總金額
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void gvData_CustomSummaryCalculate(object sender, DevExpress.Data.CustomSummaryEventArgs e)
{
string tagName = (e.Item as GridSummaryItem).Tag.ToString();
if (e.SummaryProcess == CustomSummaryProcess.Finalize)
{
if (_dtSummaryTable!=null && _dtSummaryTable.Rows.Count > 0 && tagName == "TotalReceiveMoney") //TotalReceiveMoney標識,格式化小數位 _dtSummaryTable:從數據查詢出來的彙總表
{
e.TotalValue = DataTypeConvert.ToDecimal(_dtSummaryTable.Rows[0][tagName]);
}
else
{
e.TotalValue = DataTypeConvert.ToInt16(_dtSummaryTable.Rows[0][tagName]);
}
}
}
效果圖如下: