0

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...

Devasayal
  • 40
  • 8
Belzelga
  • 143
  • 1
  • 5
  • 16

3 Answers3

1

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.

Ilkka
  • 306
  • 1
  • 7
1

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

Vikram Sharma
  • 377
  • 1
  • 8
  • 21
1

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()));
}
Magnus
  • 45,362
  • 8
  • 80
  • 118
Ullas
  • 11,450
  • 4
  • 33
  • 50