I am trying to extract a value from a dropdownlist.I am usiing dropdownlists to store the date of birth for an application.I have the years and months to output correct.I have am having a problem in getting the days of the month to sync with the number of days in a month.here is the code I am using .
int month = Convert.ToInt32(DropDownList1.SelectedValue);
days in month
Are you using the names of the months? If so, ToInt32 won't work. ToInt32 only expects numbers-as-text. It wouldn't know what to do with the name of a month, or anything else for that matter.
You may try: http://stackoverflow.com/questions/258793/how-to-parse-a-month-name-string-to-an-integer-for-comparison-in-c
Alternatively, you can just use DropDownList1.SelectedIndex (and add 1 if you need to).
You may try: http://stackoverflow.com/questions/258793/how-to-parse-a-month-name-string-to-an-integer-for-comparison-in-c
Alternatively, you can just use DropDownList1.SelectedIndex (and add 1 if you need to).
Did you try DateTime.DaysInMonth method? You can make 2 dropdown list, one to select the month and when that is selected, it populates the other dropdown list with the appropriate number of days. If you use this method, you can use both numerical and string representations for months.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement