首页 > 解决方案 > 刷新页面以显示当前时间的统计信息

问题描述

Ι 有一个页面可以从特定日期和时间带回gridview(硬编码)

我怎样才能改变这一点,以便数据显示今天的统计数据?我还希望它在特定时间开始,然后在给定时间后重置,例如 6am-2pm - 2pm-10pm - 10pm - 6am。

 public void Refreshdata(int selectedProduct)
        {
            BizManager biz = new BizManager();


            GridView1.DataSource = biz.GetPacktstatisticsForShift(new DateTime(2016, 6, 10, 6, 0, 0)
                , new DateTime(2016, 6, 10, 13, 59, 59)
                , selectedProduct).DefaultView;
            GridView1.DataBind();

 public void Dropdownlist1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int productId;
                if(int.TryParse(DropDownList1.SelectedValue, out productId))
                    Refreshdata(productId);

标签: c#asp.net

解决方案


只需向方法添加更多参数并传递它们:

public void Refreshdata(int selectedProduct, DateTime shiftStart, DateTime shiftEnd)
{
    BizManager biz = new BizManager();

    GridView1.DataSource = biz.GetPacktstatisticsForShift(
          shiftStart
        , shiftEnd
        , selectedProduct).DefaultView;
    GridView1.DataBind();
} 

public void Dropdownlist1_SelectedIndexChanged(object sender, EventArgs e)
{
    DateTime shiftStart = DateTime.Today;
    DateTime shiftEnd = DateTime.Today.AddDays(1).AddMinutes(-1);
    int productId;
        if(int.TryParse(DropDownList1.SelectedValue, out productId))
            Refreshdata(productId, shiftStart, shiftEnd);
}

推荐阅读