_javascript Techniques for date controls based on ASP.net and JavaScript control

Source: Internet
Author: User

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"));
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.