65.9K
CodeProject 正在变化。 阅读更多。
Home

动态月份名称 DropDownList

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.98/5 (17投票s)

Aug 27, 2006

CPOL
viewsIcon

103401

用月份名称填充 DropDownList 并设置当前月份选中的方法。

如何创建一个包含月份名称的下拉列表
#region Method to Fill the a DropDownList with Month Names and set the Current Month Selected
        /// <summary>
        /// fills a dropDownlist with month list.
        /// </summary>
        /// The DropDown List that will Hold the Months.
        /// if set to <c>true</c> the Current Month will be selected.
        public void GetMyMonthList(DropDownList MyddlMonthList,bool SetCurruntMonth)
        {
            DateTime month = Convert.ToDateTime("1/1/2000");
            for (int i = 0; i < 12; i++)
            {

                DateTime NextMont = month.AddMonths(i);
                ListItem list = new ListItem();
                list.Text = NextMont.ToString("MMMM");
                list.Value = NextMont.Month.ToString();
                MyddlMonthList.Items.Add(list);
            }
            if (SetCurruntMonth == true)
            {
                MyddlMonthList.Items.FindByValue(DateTime.Now.Month.ToString()).Selected = true;
            }
            

        }
        #endregion
就这样,祝您编码愉快!
© . All rights reserved.