歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

C# 循環生成年份月份綁定到下拉列表框

C# 循環生成年份月份綁定到下拉列表框:

            string Year = DateTime.Now.Date.Year.ToString();
            int intYear = Convert.ToInt32(Year)+1;
            int chaYear = intYear - 2011;
            string[] Yearlist;
            Yearlist= new string[chaYear];
            for (int i = 0; i < chaYear; i++)
            {
                Yearlist[i] = (2011 + i).ToString();
            }
            bcbyear.DataSource = Yearlist;
            bcbyear.DataBind();
            bcbyear.SelectedIndex = 0;

            string[] MonthList;
            MonthList = new string[12];
            for (int i = 0; i < 12; i++)
            {
                MonthList[i] = (i+1).ToString("00");
            }
            Bdpmonth1.DataSource = MonthList;
            Bdpmonth1.DataBind();
            Bdpmonth1.SelectedIndex = 0;

Copyright © Linux教程網 All Rights Reserved