case

日期间隔计算
// Returns the number of days between the current 
// date/time and hiredDate
TimeSpan ts = DateTime.Now.Subtract(employee.HireDate);
return ts.Days.ToString("#,##0");



//GridView的页脚中显示统计信息
// 类范围,累积合计的变量……
 2decimal _totalUnitPrice = 0m;
 3int _totalNonNullUnitPriceCount = 0;
 4int _totalUnitsInStock = 0;
 5int _totalUnitsOnOrder = 0;
protected void ProductsInCategory_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // Reference the ProductsRow via the e.Row.DataItem property
            Northwind.ProductsRow product = (Northwind.ProductsRow)((System.Data.DataRowView)e.Row.DataItem).Row;
            //……增加累积合计……
            // Increment the running totals (if they're not NULL!)
            if (!product.IsUnitPriceNull())
            {
                _totalUnitPrice += product.UnitPrice;
                _totalNonNullUnitPriceCount++;
            }

            if (!product.IsUnitsInStockNull())
                _totalUnitsInStock += product.UnitsInStock;

            if (!product.IsUnitsOnOrderNull())
                _totalUnitsOnOrder += product.UnitsOnOrder;
        }
        else if (e.Row.RowType == DataControlRowType.Footer)
        {
            /// 确定平均单价
            decimal avgUnitPrice = _totalUnitPrice / (decimal)_totalNonNullUnitPriceCount;

            //// 在相应的单元格中显示统计数据 Display the summary data in the appropriate cells
            e.Row.Cells[1].Text = "Avg.: " + avgUnitPrice.ToString("c");
            e.Row.Cells[2].Text = "Total: " + _totalUnitsInStock.ToString();
            e.Row.Cells[3].Text = "Total: " + _totalUnitsOnOrder.ToString();
        }
    }

posted @ 2007-03-16 17:40  子午  阅读(288)  评论(0编辑  收藏  举报