コード例 #1
0
        protected void DropY_SelectedIndexChanged(object sender, EventArgs e)
        {
            int m = DateTime.Now.Month;
            int y = Convert.ToInt32(DropY.SelectedValue.ToString());

            DropM.Items.Clear();
            if (y != DateTime.Now.Year)
            {
                m = 1;
            }
            for (int i = m; i < 13; i++)
            {
                DropM.ClearSelection();
                ListItem item = new ListItem(i.ToString(), i.ToString());
                if (item.Value.ToString() == DateTime.Now.Month.ToString())
                {
                    item.Selected = true;
                }
                DropM.Items.Add(item);
            }
        }
コード例 #2
0
        //绑定日期年
        protected void DataDp()
        {
            for (int i = DateTime.Now.Year; i < DateTime.Now.Year + 2; i++)
            {
                ListItem item = new ListItem(i.ToString(), i.ToString());
                if (item.Value.ToString() == DateTime.Now.Year.ToString())
                {
                    item.Selected = true;
                }
                DropY.Items.Add(item);
            }

            int y = Convert.ToInt32(DropY.SelectedValue.ToString());
            int m = DateTime.Now.Month;

            if (y != DateTime.Now.Year)
            {
                m = 1;
            }
            for (int i = m; i < 13; i++)
            {
                DropM.ClearSelection();
                ListItem item = new ListItem(i.ToString(), i.ToString());
                if (item.Value.ToString() == DateTime.Now.Month.ToString())
                {
                    item.Selected = true;
                }
                DropM.Items.Add(item);
            }

            int ms   = Convert.ToInt32(DropM.SelectedValue.ToString());
            int Dsum = 31;

            switch (ms)
            {
            case 1:
                Dsum = 31;
                break;

            case 2:
                if ((((y % 4) == 0) && ((y % 100) != 0)) || ((y % 400) == 0))
                {
                    Dsum = 29;
                }
                else
                {
                    Dsum = 28;
                }
                break;

            case 3:
                Dsum = 31;
                break;

            case 4:
                Dsum = 30;
                break;

            case 5:
                Dsum = 31;
                break;

            case 6:
                Dsum = 30;
                break;

            case 7:
                Dsum = 31;
                break;

            case 8:
                Dsum = 31;
                break;

            case 9:
                Dsum = 30;
                break;

            case 10:
                Dsum = 31;
                break;

            case 11:
                Dsum = 30;
                break;

            case 12:
                Dsum = 31;
                break;
            }
            //日
            for (int i = 1; i <= Dsum; i++)
            {
                ListItem item = new ListItem(i.ToString(), i.ToString());
                if (item.Value.ToString() == DateTime.Now.Day.ToString())
                {
                    item.Selected = true;
                }
                DropD.Items.Add(item);
            }
        }