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.
[CODE=c#]public string Populate_MonthL ist()
{
drpCalMonth.Ite ms.Add("January ");
drpCalMonth.Ite ms.Add("Februar y");
drpCalMonth.Ite ms.Add("March") ;
drpCalMonth.Ite ms.Add("April") ;
drpCalMonth.Ite ms.Add("May");
drpCalMonth.Ite ms.Add("June");
drpCalMonth.Ite ms.Add("July");
drpCalMonth.Ite ms.Add("August" );
drpCalMonth.Ite ms.Add("Septemb er");
drpCalMonth.Ite ms.Add("October ");
drpCalMonth.Ite ms.Add("Novembe r");
drpCalMonth.Ite ms.Add("Decembe r");
string strMonth;
strMonth = DateTime.Now.To String("MMMM");
drpCalMonth.Ite ms.FindByValue( strMonth).Selec ted = true;
return (strMonth);
}
public int DaysInMonth(str ing strMonth, string strYear)
{
string strDay;
// Get the current date to get the Year
DateTime d = new DateTime();
// Here Year is got from current date.
var dd = new Date(strYear, strMonth, 0);
// drpCalDay =
// return dd.getDate();
}
// Avoid Leap Year
function textDate(value)
{
var sel = document.forms[0].date;
// Clear the select
sel.options.len gth = 0;
// Get the no of days in that month
var NoOfDays = DaysInMonth(val ue);
// Now for that no of dates you loop and build the select
for(var i=1;i<=NoOfDays ;i++)
{
// Create new option
var option = new Option(i, "Value" + i);
// Add the new option it to the select
sel.options[i] = option;
}
}
public string Populate_YearLi st()
{
int intYear;
// Year list can be changed by changing the lower and upper
// limits of the For statement
for (intYear = DateTime.Now.Ye ar - 18; intYear >= DateTime.Now.Ye ar - 99; intYear--)
{
drpCalYear.Item s.Add(intYear.T oString());
}
string strYear;
strYear = DateTime.Now.To String("yyyy");
drpCalYear.Item s.FindByValue(s trYear).Selecte d = true;
return (strYear);
}[/CODE]
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.
[CODE=c#]public string Populate_MonthL ist()
{
drpCalMonth.Ite ms.Add("January ");
drpCalMonth.Ite ms.Add("Februar y");
drpCalMonth.Ite ms.Add("March") ;
drpCalMonth.Ite ms.Add("April") ;
drpCalMonth.Ite ms.Add("May");
drpCalMonth.Ite ms.Add("June");
drpCalMonth.Ite ms.Add("July");
drpCalMonth.Ite ms.Add("August" );
drpCalMonth.Ite ms.Add("Septemb er");
drpCalMonth.Ite ms.Add("October ");
drpCalMonth.Ite ms.Add("Novembe r");
drpCalMonth.Ite ms.Add("Decembe r");
string strMonth;
strMonth = DateTime.Now.To String("MMMM");
drpCalMonth.Ite ms.FindByValue( strMonth).Selec ted = true;
return (strMonth);
}
public int DaysInMonth(str ing strMonth, string strYear)
{
string strDay;
// Get the current date to get the Year
DateTime d = new DateTime();
// Here Year is got from current date.
var dd = new Date(strYear, strMonth, 0);
// drpCalDay =
// return dd.getDate();
}
// Avoid Leap Year
function textDate(value)
{
var sel = document.forms[0].date;
// Clear the select
sel.options.len gth = 0;
// Get the no of days in that month
var NoOfDays = DaysInMonth(val ue);
// Now for that no of dates you loop and build the select
for(var i=1;i<=NoOfDays ;i++)
{
// Create new option
var option = new Option(i, "Value" + i);
// Add the new option it to the select
sel.options[i] = option;
}
}
public string Populate_YearLi st()
{
int intYear;
// Year list can be changed by changing the lower and upper
// limits of the For statement
for (intYear = DateTime.Now.Ye ar - 18; intYear >= DateTime.Now.Ye ar - 99; intYear--)
{
drpCalYear.Item s.Add(intYear.T oString());
}
string strYear;
strYear = DateTime.Now.To String("yyyy");
drpCalYear.Item s.FindByValue(s trYear).Selecte d = true;
return (strYear);
}[/CODE]
Comment