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

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

  • 相关阅读:
    C语言I博客作业08
    作业7
    作业6
    作业5
    作业--4
    java基础学习--I/O流
    刷题记录--[CISCN2019 华北赛区 Day2 Web1]Hack World
    ADB测试Android真机
    sqli-labs通关笔记
    Tensorflow入门
  • 原文地址:https://www.cnblogs.com/shirley-w/p/4073187.html
Copyright © 2011-2022 走看看