ASP.NET中如何实现日期下拉框呀?

 我来答
帮助_li
推荐于2016-05-11 · TA获得超过2140个赞
知道大有可为答主
回答量:1288
采纳率:65%
帮助的人:728万
展开全部
我的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));
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式