Sign in to follow this  
phil67rpg

days in month

Recommended Posts

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);

Share this post


Link to post
Share on other sites
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). Edited by Nypyren

Share this post


Link to post
Share on other sites
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. Edited by NDraskovic

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this