views:

29

answers:

1

i need a dropdownlist to show current month and year (January 2010) till January 2011, and an additional record of January 2011 +. But I want to save this in the database as 01/01/2010 format. also if the user selects current month then the record should be getdate() to go in database, else for any other month it should be 02/01/2010 (date = 01, first day of month). how do i do this in aspx.vb .net. i wrote a function to populate the dorpdownlist - Public Sub Load_dates(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

this function only shows number like 01 2010 and 02 2010. how can i format this to show january 2010 and february 2010 and so on. please advice

A: 

To populate the list, you should use the DateTime Object's ToString() method. If you just want the name of the month, that is .ToString("MMMM") and that will return "January" "February" etc.

Then you can store this object in the database.

When you retrieve it from the DB you can just apply .ToString() for however you want to display it.

taylonr