473,405 Members | 2,167 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,405 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;
  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 6029
gits
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

2
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.