
ASP.NET中如何实现日期下拉框呀?
1个回答
展开全部
我的DropDownList1是月,DropDownList2是年,DropDownList3是日。年和月用反了。呵呵
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
int i;
ArrayList month=new ArrayList();
for(i=1;i<=12;i++)
num.Add(i);
this.DropDownList1.DataSource=month;
this.DropDownList1.DataBind();
//以上初始化月
int j;
ArrayList year=new ArrayList();
for(j=2000;j<=2020;j++)
year.Add(j);
this.DropDownList2.DataSource=year;
this.DropDownList2.DataBind();
//以上初始化年
this.DropDownList1.AutoPostBack=true;
this.DropDownList2.AutoPostBack=true;
}
}
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
day(this.DropDownList1.SelectedValue,Convert.ToInt16(this.DropDownList2.SelectedValue));
}
private void day(string d,int year)
{
switch(d)
{
case "1":
case "3":
case "5":
case "7":
case "8":
case "10":
case "12":
daynum("31");
break;
case "2":
if((year%4==0&&year%100!=0)||(year%400==0))
daynum("29");
else
daynum("28");
break;
default:
daynum("30");
break;
}
}
private void daynum(string num)
{
int i;
ArrayList day=new ArrayList();
for(i=1;i<=Convert.ToInt16(num);i++)
day.Add(i);
this.DropDownList3.DataSource=day;
this.DropDownList3.DataBind();
}
private void DropDownList2_SelectedIndexChanged(object sender, System.EventArgs e)
{
day(this.DropDownList1.SelectedValue,Convert.ToInt16(this.DropDownList2.SelectedValue));
}
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
int i;
ArrayList month=new ArrayList();
for(i=1;i<=12;i++)
num.Add(i);
this.DropDownList1.DataSource=month;
this.DropDownList1.DataBind();
//以上初始化月
int j;
ArrayList year=new ArrayList();
for(j=2000;j<=2020;j++)
year.Add(j);
this.DropDownList2.DataSource=year;
this.DropDownList2.DataBind();
//以上初始化年
this.DropDownList1.AutoPostBack=true;
this.DropDownList2.AutoPostBack=true;
}
}
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
day(this.DropDownList1.SelectedValue,Convert.ToInt16(this.DropDownList2.SelectedValue));
}
private void day(string d,int year)
{
switch(d)
{
case "1":
case "3":
case "5":
case "7":
case "8":
case "10":
case "12":
daynum("31");
break;
case "2":
if((year%4==0&&year%100!=0)||(year%400==0))
daynum("29");
else
daynum("28");
break;
default:
daynum("30");
break;
}
}
private void daynum(string num)
{
int i;
ArrayList day=new ArrayList();
for(i=1;i<=Convert.ToInt16(num);i++)
day.Add(i);
this.DropDownList3.DataSource=day;
this.DropDownList3.DataBind();
}
private void DropDownList2_SelectedIndexChanged(object sender, System.EventArgs e)
{
day(this.DropDownList1.SelectedValue,Convert.ToInt16(this.DropDownList2.SelectedValue));
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询