C# 数组作为DropDownList数据源实例---年月日加载

来源:互联网 发布:linux查看hba卡驱动 编辑:程序博客网 时间:2024/05/22 18:04
        protected void Page_Load(object sender, EventArgs e)        {                        bindday(yearDropDL.SelectedValue, monthDropDL.SelectedValue);        }        public void bindday(string y, string m)        {            int year = int.Parse(y);            int month = int.Parse(m);            int[] lp = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 };            int[] nlp = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28 };            int[] lm = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };            int[] bm = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };            if (month == 2)            {                if (year % 100 == 0)                {                    if (year % 400 == 0)                    {                        dayDropDL.DataSource = lp;                        dayDropDL.DataBind();                    }else                   {                    dayDropDL.DataSource = nlp;                    dayDropDL.DataBind();                   }                }                else if (year % 4 == 0)                {                    dayDropDL.DataSource = lp;                    dayDropDL.DataBind();                }                else                {                    dayDropDL.DataSource = nlp;                    dayDropDL.DataBind();                }            }            else if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)            {                dayDropDL.DataSource = bm;                dayDropDL.DataBind();            }            else            {                dayDropDL.DataSource = lm;                dayDropDL.DataBind();            }