mathieu cupryk
Top achievements
Rank 1
mathieu cupryk
asked on 07 Sep 2009, 08:15 PM
I need a dropdownlist for date of birth.
I built a control for this. I don't like the calendar control for this.
I like the old style. dropdownlist.
I built a control for this. I don't like the calendar control for this.
I like the old style. dropdownlist.
3 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 08 Sep 2009, 06:21 AM
Hi,
Give a try with the following approach and see whether this is what you require.
ASPX:
CS:
Thanks
Princy
Give a try with the following approach and see whether this is what you require.
ASPX:
| <telerik:RadComboBox ID="birthDayCombo" runat="server"> |
| </telerik:RadComboBox> |
| <telerik:RadComboBox ID="birthMonthCombo" runat="server"> |
| </telerik:RadComboBox> |
| <telerik:RadComboBox ID="birthYearCombo" runat="server"> |
| </telerik:RadComboBox> |
CS:
| protected void Page_Init(object sender, EventArgs e) |
| { |
| // populate the days drop down |
| for (int day = 1; day < 32; day++) |
| { |
| RadComboBoxItem li = new RadComboBoxItem(); |
| li.Text = day.ToString(); |
| li.Value = day.ToString(); |
| birthDayCombo.Items.Add(li); |
| } |
| // populate the Month drop down |
| DateTimeFormatInfo dtfi = new DateTimeFormatInfo(); |
| for (int month = 1; month < 13; month++) |
| { |
| RadComboBoxItem li = new RadComboBoxItem(); |
| li.Text = dtfi.GetMonthName(month) + " (" + month.ToString() + ")"; |
| li.Value = month.ToString(); |
| birthMonthCombo.Items.Add(li); |
| } |
| // populate the years drop down |
| int startYear = System.DateTime.Now.Year; |
| for (int year = startYear; year > startYear - 100; year--) |
| { |
| RadComboBoxItem li = new RadComboBoxItem(); |
| li.Text = year.ToString(); |
| li.Value = year.ToString(); |
| birthYearCombo.Items.Add(li); |
| } |
| } |
Thanks
Princy
0
mathieu cupryk
Top achievements
Rank 1
answered on 10 Sep 2009, 07:17 PM
Does this fix the leap year.
If someone selects a certain year and feb. then it should update the dropdown to 28 or 29 days.
If someone selects a certain year and feb. then it should update the dropdown to 28 or 29 days.
0
Accepted
Princy
Top achievements
Rank 2
answered on 11 Sep 2009, 07:46 AM
Hello,
You can hide/show the RadComboBoxItem using show()/hide() method from client. I tried adding following client side code for setting day combobox value according to month and year selection (if leap year is selected).
ASPX:
JavaScript:
Thanks,
Princy.
You can hide/show the RadComboBoxItem using show()/hide() method from client. I tried adding following client side code for setting day combobox value according to month and year selection (if leap year is selected).
ASPX:
| <telerik:RadComboBox ID="birthDayCombo" runat="server"> |
| </telerik:RadComboBox> |
| <telerik:RadComboBox ID="birthMonthCombo" OnClientSelectedIndexChanged="OnClientSelectedIndexChanged" runat="server"> |
| </telerik:RadComboBox> |
| <telerik:RadComboBox ID="birthYearCombo" OnClientSelectedIndexChanged="OnClientSelectedIndexChanged" runat="server"> |
| </telerik:RadComboBox> |
JavaScript:
| <script type="text/javascript"> |
| function OnClientSelectedIndexChanged(sender, args) |
| { |
| var comboM; |
| var comboY; |
| var comboD = $find('<%= birthDayCombo.ClientID %>'); |
| if(sender.get_id() == 'birthMonthCombo') |
| { |
| comboY = $find('<%= birthYearCombo.ClientID %>'); |
| comboM = sender; |
| } |
| else |
| { |
| comboM = $find('<%= birthMonthCombo.ClientID %>'); |
| comboY = sender; |
| } |
| var mode = comboY.get_text()%4; |
| if(!mode && comboM.get_text() == 'February (2)') |
| { |
| leapYear(); |
| } |
| else |
| { |
| if (comboM.get_text() == 'February (2)') |
| { |
| comboD.findItemByText('30').hide(); |
| comboD.findItemByText('31').hide(); |
| comboD.findItemByText('29').hide(); |
| } |
| else |
| { |
| comboD.findItemByText('30').show(); |
| comboD.findItemByText('31').show(); |
| comboD.findItemByText('29').show(); |
| } |
| } |
| } |
| function leapYear() |
| { |
| var comboD = $find('<%= birthDayCombo.ClientID %>'); |
| comboD.findItemByText('30').hide(); |
| comboD.findItemByText('31').hide(); |
| comboD.findItemByText('29').show(); |
| } |
| </script> |
Thanks,
Princy.