如何在asp.net中增加和减少日期

时间:2016-05-28 12:34:04

标签: asp.net

如何在asp.net中增加和减少日期..

我尝试过以下代码..

或者有没有像javascript一样的替代品??

    {
      string dt;
    protected void Page_Load(object sender, EventArgs e)
    {
        dt = DateTime.Now.ToShortDateString().ToString();
        date.Text = dt;
    }

    protected void decr_Click(object sender, EventArgs e)
    {
        date.Text = Convert.ToDateTime(date.Text).AddDays(-1).ToShortDateString().ToString();         
    }

    protected void incr_Click(object sender, EventArgs e)
    {
        date.Text =Convert.ToDateTime(date.Text).AddDays(1).ToShortDateString().ToString();          
    }

1 个答案:

答案 0 :(得分:0)

Page_Load

中包含if (!Page.IsPostBack)事件的代码
 protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                dt = DateTime.Now.ToShortDateString().ToString();
                date.Text = dt;
            }
        }