时间:2021-05-25
控件效果如下:
从左到右:month,day,year
.cs文件初始化这三个下拉列表
复制代码 代码如下:
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;
}
js代码如下(自己写的,不保证完全正确啊):
复制代码 代码如下:
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"));
}
}
}
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
我们开发ASP.NET站点时,如果将jQueryUIDatepicker与ASP.NET的验证控件(如:RequiredFieldValidator)组合使用:
html中的select标签,也是asp.net中的asp:DropDownList控件。javascript对它们的操作一、基础理解复制代码代码如下:vare
ASP.NET网站页和控件框架的建设开发ASP.NET页和控件框架是一种编程框架,它在Web服务器上运行,可以动态地生成和呈现ASP.NET网页。可以从任何浏览
此控件是asp.net中的验证控件RequiredFieldValidator,RangeValidator,RegularExpressionValidato
功能:可以把某个asp.net控件替换成自定义的控件pages的tagMapping元素(ASP.NET设置架构)定义一个标记类型的集合,这些标记类型在编译时重