The control effects are as follows:
From left to right: Month,day,year
The. cs file initializes these three drop-down lists
Copy Code code as follows:
private void Bindbirthday (int day, int month, int year)
{
int daynow = day;
int monnow = month;
int yearnow = year;
Binding Month
for (int i = 1; I <= i++)
{
DDLBIRMON.ITEMS.ADD (New ListItem (i.ToString (), i.ToString ()));
}
DDLBIRMON.ITEMS[MONNOW-1]. Selected = true;
Binding Day
int daysofmonth = Datetime.daysinmonth (Yearnow, Monnow);
for (int i = 1; I <= daysofmonth; i++)
{
DDLBIRDAY.ITEMS.ADD (New ListItem (i.ToString (), i.ToString ()));
}
DDLBIRDAY.ITEMS[DAYNOW-1]. Selected = true;
Binding year
for (int i = i > 0; i--)
{
DDLBIRYEAR.ITEMS.ADD (New ListItem (yearnow-i). ToString (), (yearnow-i). ToString ()));
}
for (int i = 0; i < i++)
{
DDLBIRYEAR.ITEMS.ADD (The new ListItem (Yearnow + i). ToString (), (Yearnow + i). ToString ()));
}
DdlBirYear.Items.FindByValue (Yearnow.tostring ()). Selected = true;
}
JS code is as follows (own write, do not guarantee exactly right AH):
Copy Code code as follows:
function Changeday () {
var month = document.getElementById ("<%=ddlbirmon.clientid%>");
var year = document.getElementById ("<%=ddlbiryear.clientid%>");
var day = document.getElementById ("<%=ddlbirday.clientid%>");
if (Month.selectedindex = 3 | | month.selectedindex = 5 | | | month.selectedindex = 8 | | month.selectedindex = = 10) {
if (day.length = = 31) {
if (day.options[30].selected = = True) {
Day.options[29].selected = true;
}
Day.remove (30);
}
}
else{
while (Day.length < 31) {
Day.add (New Option (day.length+1,day.length+1));
}
}
if (Month.selectedindex = = 1) {
if (Day.length > 28) {
if (Day.selectedindex = = 28) {
Day.options[27].selected = true;
}
while (Day.length > 28) {
Day.remove (day.length-1);
}
}
var sy = year.options[year.selectedindex].value;
if (sy% 4 = 0 && sy% 100!= 0) | | (sy% 400==0)) {
Day.add (New Option ("29", "29"));
}
}
}