Belzelga
Belzelga

Reputation: 153

Birthday Dropdownlist ASP.NET C#

I am making an input for birthday, how do I make an if-else statement in a dropdownlist?

Months like February only have 28/29 days in it while the rest have 30 or 31...

It would be strange if the user can select month 'April' and day '31'

What I have done is making a label for 'Birthday' .. added another label for each 'day' 'month' and 'year'

And 3 dropdownlists for each label...

Upvotes: 0

Views: 3929

Answers (3)

Ullas
Ullas

Reputation: 11556

Try this Belzelga......

Add years in your yearDropDownList and months in monthDropDownList... In yearDropDownList's SelectedIndexChanged event check whether the selected year is a leap year or not. Then according to the selection of month add days.

Use the following example code for adding days:

for (int i = 0; i <= 30; i++)
{
   dayDropDownList.Items.Add(new ListItem(i.ToString(),i.ToString()));
}

Upvotes: 1

Vikram Sharma
Vikram Sharma

Reputation: 387

I would strongly recommend using a Javascript/Jquery calendar. These are here to make life simpler for a developer and let him focus on more specific things. There are so many options out there.
One such option is DHTML goodies calendar.
http://www.dhtmlgoodies.com/?page=calendarScripts

Upvotes: 1

Ilkka
Ilkka

Reputation: 306

You have basically three choices:

  1. Write a javascript function to add/remove days from the DropDownList when user selects a month.

  2. Set AutoPostBack="true" on the month DropDownList and on the server side add/remove days from the DropDownList. This is the easiest way to go, if you have no experience in writing javascript.

  3. Use a control like jQuery datepicker.

Upvotes: 1

Related Questions