473,487 Members | 2,674 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dropdownlist date selector(no calendar) in AJAX C#.

24 New Member
I have been looking for code to show a dropdownlist date for a person to select there date of birth without calendar.
I have the below code but if there is some code in Ajax Javascript I will use it.
I feel like I am inventing the wheel.
I have to make sure that all these are c# and return the appropriate value.
I appreciate any help.

Expand|Select|Wrap|Line Numbers
  1. public string Populate_MonthList()
  2.         {
  3.             drpCalMonth.Items.Add("January");
  4.             drpCalMonth.Items.Add("February");
  5.             drpCalMonth.Items.Add("March");
  6.             drpCalMonth.Items.Add("April");
  7.             drpCalMonth.Items.Add("May");
  8.             drpCalMonth.Items.Add("June");
  9.             drpCalMonth.Items.Add("July");
  10.             drpCalMonth.Items.Add("August");
  11.             drpCalMonth.Items.Add("September");
  12.             drpCalMonth.Items.Add("October");
  13.             drpCalMonth.Items.Add("November");
  14.             drpCalMonth.Items.Add("December");
  15.             string strMonth;
  16.  
  17.             strMonth = DateTime.Now.ToString("MMMM");
  18.             drpCalMonth.Items.FindByValue(strMonth).Selected = true;
  19.             return (strMonth);
  20.         }
  21.  
  22.         public int DaysInMonth(string strMonth, string strYear) 
  23.         {
  24.             string strDay;
  25.             // Get the current date to get the Year
  26.             DateTime d = new DateTime();
  27.             // Here Year is got from current date. 
  28.  
  29.             var dd = new Date(strYear, strMonth, 0);
  30.            // drpCalDay = 
  31.            // return dd.getDate();
  32.        }
  33.  
  34.        // Avoid Leap Year
  35.        function textDate(value)
  36.        {
  37.            var sel = document.forms[0].date;
  38.            // Clear the select
  39.            sel.options.length = 0;
  40.            // Get the no of days in that month
  41.            var NoOfDays = DaysInMonth(value);
  42.            // Now for that no of dates you loop and build the select
  43.            for(var i=1;i<=NoOfDays;i++)
  44.            {
  45.               // Create new option
  46.               var option = new Option(i, "Value" + i); 
  47.               // Add the new option it to the select
  48.               sel.options[i] = option; 
  49.            }
  50.        }
  51.  
  52.  
  53.  
  54.         public string Populate_YearList()
  55.         {
  56.             int intYear;
  57.  
  58.  
  59.             // Year list can be changed by changing the lower and upper 
  60.             // limits of the For statement
  61.             for (intYear = DateTime.Now.Year - 18; intYear >= DateTime.Now.Year - 99; intYear--)
  62.             {
  63.                 drpCalYear.Items.Add(intYear.ToString());
  64.             }
  65.             string strYear;
  66.  
  67.             strYear = DateTime.Now.ToString("yyyy");
  68.             drpCalYear.Items.FindByValue(strYear).Selected = true;
  69.             return (strYear);
  70.  
  71.         }
Jul 26 '08 #1
1 6034
gits
5,390 Recognized Expert Moderator Expert
what do you want with AJAX here? AJAX is just a an async XMLHttpRequest that allows you to request some data in the background and update a part of a page instead of reloading the entire page ...

kind regards
Jul 28 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1729
by: Si | last post by:
Hi all, I have an events database (Access) that contains 2 fields, StartDate and EndDate. The fields are set as Date/Time long date. The server is UK date format (dd/mm/yyyy) I have a small...
7
8753
by: John Baker | last post by:
HI: I have a date, and am trying to do something that SHOULD be very simple -- but finding a problem. Assume the date is 01/01/03. I wish to make the date 02/01/03, and then next month 03/01/03...
6
7483
by: Jason | last post by:
I have two drop down lists on my asp.net page, the second of which needs to be filled in based on the selection in the first dropdownlist. The catch however, is that it must occur without a...
1
1466
by: Reidar | last post by:
In a windows form, is it possible to use a date calendar in a date-field in a datagridview? regards reidarT
3
3120
by: Joey | last post by:
Does anyone know how to set a minimum selectable date in the calendar server control that come with VS2005? I do not want to use validators...I want the days before the selectable period to be...
2
1422
by: Takeadoe | last post by:
Dear NG - One would think that someone has done this before, but I need to convert a text string in the following format 09201962 to a date. The fact that it is missing "/" seems to be...
3
1154
by: abprules | last post by:
I seem to be having a problem with the default value of a field being updated on entry of a form. I have the default value in the field as =Date() but it does not update with the current date. Any...
1
2389
by: rdowdall | last post by:
Hello - Ive been struggling with a javascript date validator to check that the date is no earlier than the first day of the previous month. Can someone help? Thanks
3
6798
by: Keith Wilby | last post by:
How do you find the earliest of a set of dates in a field using a query? I thought using "min" in a totals query would work but it seems to treat the date like text. I feel a forehead slapping...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7181
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5442
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4874
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
267
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.