Wednesday, March 21, 2012

populating a drop down list based on the date

Hi, I'm looking to populate a drop down list with the month and year for the next 12 months from the current date, codeing in C#

any help would be great, thanks

this will show the next 12 months in a textbox, not to hard for you to convert to a drop down list

 DateTime date =new DateTime(2007, 02, 11);for (int i = 1; i <= 12; i++) { txtOutput.Text += date.AddMonths(i).ToShortDateString() +"\r"; }

check out this code below... its working for me...

protected void Button2_Click(object sender, EventArgs e) {for (int iCount = 0; iCount < 12; iCount++) { DropDownList1.Items.Add(DateTime.Now.AddMonths(iCount + 1).ToString("MMMM"));if (DropDownList2.Items.FindByText(DateTime.Now.AddMonths(iCount + 1).ToString("yyyy")) ==null) DropDownList2.Items.Add(DateTime.Now.AddMonths(iCount + 1).ToString("yyyy")); } }

hope it helps./.

0 comments:

Post a Comment