The control effect is as follows:
From left to right: month, day, year
. CS file initialization drop-down lists
CopyCode The Code is 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 <= 12; 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 = 20; I> 0; I --)
{
Ddlbiryear. Items. Add (New listitem (yearnow-I). tostring (), (yearnow-I). tostring ()));
}
For (INT I = 0; I <20; I ++)
{
Ddlbiryear. Items. Add (New listitem (yearnow + I). tostring (), (yearnow + I). tostring ()));
}
Ddlbiryear. Items. findbyvalue (yearnow. tostring (). Selected = true;
}
The JS Code is as follows (self-written, not necessarily completely correct ): Copy code The Code is 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 "));
}
}
}