473,226 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

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

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;
  17.             strMonth = DateTime.Now.ToString("MMMM");
  18.             drpCalMonth.Items.FindByValue(strMonth).Selected = true;
  19.             return (strMonth);
  20.         }
  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. 
  29.             var dd = new Date(strYear, strMonth, 0);
  30.            // drpCalDay = 
  31.            // return dd.getDate();
  32.        }
  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.        }
  54.         public string Populate_YearList()
  55.         {
  56.             int intYear;
  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;
  67.             strYear = DateTime.Now.ToString("yyyy");
  68.             drpCalYear.Items.FindByValue(strYear).Selected = true;
  69.             return (strYear);
  71.         }
Jul 26 '08 #1
1 6023
5,390 Expert Mod 4TB
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

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...
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...
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...
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
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...
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...
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...
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
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...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.