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;//设置默认值 }
时间: 2024-10-24 13:26:08