绑定月份

    private void GetMonth()
        {
            int index = 0; //定义索引
            DateTime now = DateTime.Now;
            string month = now.Month.ToString();
            if (Convert.ToInt32(month)<10)
            {
                month = "0" + month + "";
            }
            else
            {
                month = month + "";
            }
            string[] MonthList;
            MonthList = new string[12];
            for (int i = 0; i < 12; i++)
            {
                MonthList[i] = (i + 1).ToString("00") + "";
                if (MonthList[i]==month)
                {
                    index = i;//设置索引
                }
            }
            ddlMonth.DataSource = MonthList;
            ddlMonth.SelectedIndex = index;//设置默认值
        }

 

posted on 2017-07-09 17:36  选择大于努力  阅读(228)  评论(0编辑  收藏  举报

导航