zoukankan      html  css  js  c++  java
  • ObjectDataSource数据源 统计和合计

    在用ObjectDataSource数据源分页 统计有多少条数据或者合计某个单价的时候,总是显示当前页面数据的合,点下一页就是下一页的合,所以我就写了这样一个类。 以便以后复制

    代码
    /// <summary>
    /// 统计label
    /// </summary>
    private Label countLabel;
    /// <summary>
    /// 计算Lable
    /// </summary>
    private Label sumLabel;
    private Dictionary<string, Label> sumLabelDic = new Dictionary<string, Label>();
    /// <summary>
    /// 计算列名
    /// </summary>
    private string sumCellName;
    #region

    /// <summary>
    /// 统计ObjectDataSource为数据源的GridView
    /// </summary>
    /// <param name="ods">要统计GridView的ObjectDataSource</param>
    /// <param name="label">显示统计结果的Label</param>
    protected void CountODSGridView(ObjectDataSource ods, Label label)
    {
    countLabel
    = label;
    ods.Selected
    += new ObjectDataSourceStatusEventHandler(ObjectDataSourceSelectedCount);
    //页面初始化赋值委托
    //this.Load += PageLoadForSumAndCount;
    }
    /// <summary>
    /// 计算ObjectDataSource为数据源的GridView
    /// </summary>
    /// <param name="ods">要计算GridView的ObjectDataSource</param>
    /// <param name="label">显示计算结果的Label</param>
    /// <param name="cellName">计算列名</param>
    protected void SumODSGridView(ObjectDataSource ods, Label label, string cellName)
    {
    if (sumLabelDic.Keys.Count == 0)
    {

    ods.Selected
    += new ObjectDataSourceStatusEventHandler(ObjectDataSourceSelectedSum);
    }
    sumLabelDic.Add(cellName, label);

    sumLabel
    = label;
    sumCellName
    = cellName;

    //页面初始化赋值委托
    //this.Load += PageLoadForSumAndCount;
    }
    ///// <summary>a
    ///// 为统计和求和做页面加载
    ///// </summary>
    ///// <param name="sender"></param>
    ///// <param name="e"></param>
    //public void PageLoadForSumAndCount(object sender, EventArgs e){
    // if (sumLabel!=null)
    // {
    // sumLabel.Text = "0.00";
    // }
    // if (countLabel!=null)
    // {
    // countLabel.Text = "0";
    // }
    //}
    /// <summary>
    /// 统计委托
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public void ObjectDataSourceSelectedCount(Object sender, ObjectDataSourceStatusEventArgs e)
    {
    int count = 0;
    if (e.ReturnValue != null)
    {
    DataTable dt
    = (DataTable)e.ReturnValue;
    count
    = dt.Rows.Count;
    }
    countLabel.Text
    = count.ToString();
    }
    /// <summary>
    /// 计算委托
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public void ObjectDataSourceSelectedSum(Object sender, ObjectDataSourceStatusEventArgs e)
    {

    foreach (string cellName in sumLabelDic.Keys)
    {
    string sum = "";
    if (e.ReturnValue != null)
    {
    DataTable dt
    = (DataTable)e.ReturnValue;
    foreach (DataRow row in dt.Rows)
    {
    object cell = row[cellName];
    if (cell != null)
    {
    sum
    += cell + ",";
    }
    }
    }
    sumLabelDic[cellName].Text
    = sum.ToString();
    }



    // sumLabel.Text = sum.ToString();
    }

    #endregion


    }
  • 相关阅读:
    Android APK反编译
    android 安卓APP获取手机设备信息和手机号码的代码示例
    Android-- ArrayAdapter用法举例(转载)
    Android--ListView 分割线
    Android——检测TXT文件中是否含有双字节字符
    Android--------从一个包中的Avtivity创建另外另外一个包的Context
    百度地图技术大揭秘
    Lotusscript统计在线用户数
    代理中如何获取参数么
    DXL之通过程序修改Domino的设计
  • 原文地址:https://www.cnblogs.com/changlin/p/1796695.html
Copyright © 2011-2022 走看看