using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace AjaxDateRange
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                SetDates();
        }

        protected void ddlDateRange_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetDates();
        }

        private void SetDates()
        {
            dpEnd.Visible = ddlDateRange.SelectedValue != "0";
            switch (ddlDateRange.SelectedValue)
            {
                case "0":
                    dpStart.SelectedDate = DateTime.Today;
                    dpEnd.SelectedDate = DateTime.Today;

                    break;
                case "1":
                    dpStart.SelectedDate = DateTime.Today.AddDays(-7);
                    dpEnd.SelectedDate = DateTime.Today.AddDays(-1);
                    break;
                case "2":
                    dpStart.SelectedDate = DateTime.Today.AddMonths(-1);
                    dpEnd.SelectedDate = DateTime.Today.AddDays(-1);
                    break;
                case "3":
                    dpStart.SelectedDate = DateTime.Today.AddYears(-1);
                    dpEnd.SelectedDate = DateTime.Today.AddDays(-1);
                    break;
            }
        }
    }
}
