zoukankan      html  css  js  c++  java
  • DevExpress GridView 自定义实现底部汇总

    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]);
          }
      }
    }

    效果图如下:

  • 相关阅读:
    学习之路
    c
    为什么正确,还是有点bug?
    1212
    学习呀
    记录一下学习c语言的过程3.26日1
    字符串处理
    二维数组的转置
    一维数组转置
    Mybatis读取数据实战
  • 原文地址:https://www.cnblogs.com/qq-xiao/p/6121358.html
Copyright © 2011-2022 走看看