views:

278

answers:

3

i need to populate my dropdownlist with month and year values to getdate + 1 year. I also want them in text format so "January 2009 and not 1 2009. This is the code i have written to populate the values. how do i convert them to January from 1?

Public Sub Load_xxxx(ByRef DDL As System.Web.UI.WebControls.DropDownList) Try Dim i As Integer Dim j As Integer For i = Now.Year To Now.Year For j = Now.Month To Now.Month + 11 DDL.Items.Add((j.ToString) + " " + (i.ToString)) Next Next Catch ex As Exception ReportError(ex) End Try End Sub

A: 

If your just trying to convert the integer value to month name an easy way to do it would be just to create an array of strings containing the month names and use your j value as the index.

Andrew M.
A: 

How about

Dim time As DateTime = DateTime.Now
    Dim j As Integer
    For j = 0 To 11
        DDL.Items.Add((time.AddMonths(j)).ToString("MMMM"))
    Next
taylonr
A: 
Dim time As DateTime = DateTime.Now
DDL.Items.Clear()
While time <= time.AddYears(1)
    DDL.Items.Add((time.AddMonths(j)).ToString("MMMM yyyy"))
    time = time.AddMonths(1)
Next
Russell Steen