By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,636 Members | 1,181 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,636 IT Pros & Developers. It's quick & easy.

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

P: 24
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
Share this Question
Share on Google+
1 Reply


gits
Expert Mod 5K+
P: 5,343
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

Post your reply

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