gridview asp.net中的倒数计时器

时间:2017-07-08 12:05:38

标签: javascript asp.net gridview countdown

我有一个包含开始日期和结束日期的项目表。我想在asp.net中显示gridview中的倒计时到项目结束时以及它是否显示消息“Project Ended”。

1 个答案:

答案 0 :(得分:0)

我想你想显示项目的剩余天数 您可以在RowDataBound事件中执行此操作:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView rowView = (DataRowView)e.Row.DataItem;
                DateTime startDate = rowView["startDate"];
                DateTime endDate = rowView["endDate"];
                int daysRemaining = (endDate - startDate).TotalDays;
                if (daysRemaining > 0)
                   e.row.Cells[your column].Text = daysRemaining.ToString();
                else
                   e.row.Cells[your column].Text = "PROJECT ENDED";
             }
          }