日期运算

来源:互联网 发布:淘宝网上退货退款流程 编辑:程序博客网 时间:2024/05/12 06:44
 

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
     int index1;
     string today = DateTime.Today.ToString("yyyy-MM-dd");
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
        e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();
        index1 = e.Row.RowIndex;
        sid = GridView1.DataKeys[index1]["SID"].ToString();
        for (int i = 0; i < e.Row.Cells.Count; i++)
        {
           TimeSpan ts;
           ts=Convert.ToDateTime(today).Subtract(Convert.ToDateTime(Convert.ToDateTime(e.Row.Cells[3].Text)).ToString("yyyy-MM-dd")))//比如3是时间日期列来算
           if ((ts.Days > 0)&&(ts.Days < 5))//ts.Days>0)
           {
              e.Row.Cells[i].Attributes["ShowHidden('"+ sid +"')"]....//显示信息
           }
        }
     }
}

 

原创粉丝点击