綁定月份

    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;//設置默認值
        }
相關文章
相關標籤/搜索