zoukankan      html  css  js  c++  java
  • PivotGridField 中对Unbound的列赋值(除法)--数据钻取

    上一中方法(http://www.cnblogs.com/shirley-w/p/4042391.html)只能计算分子和分母均在数据区域显示的除法,用数据钻取的方法可取到在其他区域甚至visible=“false”的列值

    .aspx中<Fields>内的代码:

     <dx:PivotGridField ID="field_corr" Area="DataArea" AreaIndex="0"  FieldName="诊断符合数" ValueFormat-FormatType="Numeric" Caption="诊断符合数"></dx:PivotGridField>
    <dx:PivotGridField ID="field_Sum" Area="DataArea" AreaIndex="1"  FieldName="诊断总数"  Caption="诊断总数"></dx:PivotGridField>
    <dx:PivotGridField ID="field_compare" Area="DataArea" AreaIndex="2"  FieldName="诊断符合率" Caption="诊断符合率"  UnboundType="Decimal"></dx:PivotGridField>

    其中诊断符合率=诊断符合数/诊断总数

    除法需要在后台绑定OnCustomCellDisplayText事件:OnCustomCellDisplayText="pivotGrid_CustomCellDisplayText"

    .cs

     protected void pivotGrid_CustomCellDisplayText(object sender, PivotCellDisplayTextEventArgs e)//通过数据钻取对病案率的计算
             {
                 if (object.ReferenceEquals(e.DataField, ASPxPGDiagnosticAccordanceRate.Fields["诊断符合率"]))
                 {
                     PivotDrillDownDataSource ds = e.CreateDrillDownDataSource();
                     int corrcount = 0;
                     int Sumcount = 0;
                     for (int i = 0; i < ds.RowCount; i++)
                     {
                         PivotDrillDownDataRow row = ds[i];
                         corrcount += (int)row[field_corr];
                         Sumcount += (int)row[field_Sum];
                     }
                     if (Sumcount > 0)
                     {
                         decimal perc = (decimal) corrcount/Sumcount;
                         e.DisplayText = string.Format("{0:p}", perc);
                     }
                 }
             }

    此方法不但可以将计算值显示在界面上,而且将“诊断符合数”、“诊断总数”列放在筛选区或者其他区域(甚至不可见,但存在此项)均可以算出结果

  • 相关阅读:
    贪心算法部分题目及知识点总结
    贪心算法(农夫修泥塘)
    贪心算法部分知识点
    丑数运算 一、((输出丑数n的下标)(给定丑数输下标)) 二、((求第n个丑数是谁)(给定下标求丑数))
    关于学习STL部分学到的零碎知识点
    STL中set与map的使用以及优先队列的部分补充内容以及重载运算符的使用
    回文素数与接水问题(OJ)
    关于字符串与整数转化的问题与一些常用字符串处理函数
    部分STL简单应用知识点
    【Python小游戏】俄罗斯方块
  • 原文地址:https://www.cnblogs.com/shirley-w/p/4073187.html
Copyright © 2011-2022 走看看