Sunday, August 18, 2013

Months using dropdown list in asp.net

DateTime month = DateTime.Parse("1/1/1990");
        for (i = 0; i < 12; i++)
        {
            DateTime nmonth = month.AddMonths(i);
            string dmonth = nmonth.ToString("MMMM");
            DropDownList1.Items.Insert(i, dmonth);
        }



OR


 string str = DateTime.Now.ToShortDateString();
        DateTime cmonth = DateTime.Parse(str);
        string mon = cmonth.ToString("MMMM");
        if (DropDownList1.SelectedItem.Text != mon)
        {
            DropDownList1.ClearSelection();
            DropDownList1.Items.FindByText(mon).Selected = true;
        }

No comments:

Post a Comment