Monday, March 26, 2012

Loop over months - new at this

I am very new at this - so please excuse my ignorance...

I want to have a drop down list that displays the months of the year without having to write each month (loop from 1 to 12 and with each loop add the value, as a number, and the item, as the month name, to the drop down list).

Can someone show me how - or point me to where I can see an example of this?

Thankshello, i don't think there is a way to generate all the dates and store them in the dropdownlist, what you can do is th following:

you can store dates in a database, and then populate your ropdownlist with the values in the database.

hope this helps.
Hi Bilal,

Thank you for your response.

I did figure out how to do this - below is the code.

Private Sub Page_Load(ByVal...
If Not isPostBack
Dim i As Integer
For i = 1 To 12
Dim tempDate As String = i & "/" & 1 &"/" & Year(now())
dropDownList1.Items.Add(New ListItem(MonthName(Month(tempDate)), i))
Next
End If
End Sub

Try it - it works fine.

Later,

0 comments:

Post a Comment