62,271
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>test</title>
</head>
<body>
<form id="form1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="YearOrMonthChanged" />年
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true" OnSelectedIndexChanged="YearOrMonthChanged" />月
<asp:DropDownList ID="DropDownList3" runat="server"/>日
</form>
</body>
</html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.DataSource = Enumerable.Range(1970, 40);
DropDownList2.DataSource = Enumerable.Range(1, 12);
DropDownList3.DataSource = Enumerable.Range(1, 31);
DropDownList1.DataBind();
DropDownList2.DataBind();
DropDownList3.DataBind();
}
}
protected void YearOrMonthChanged(object sender, EventArgs e)
{
int year = Convert.ToInt32(DropDownList1.Text);
int month = Convert.ToInt32(DropDownList2.Text);
int day = Convert.ToInt32(DropDownList3.Text);
DateTime date = new DateTime(year, month, 1);
int days = (int)(date.AddMonths(1) - date).TotalDays;
DropDownList3.DataSource = Enumerable.Range(1, days);
DropDownList3.DataBind();
DropDownList3.Text = Math.Min(day, days).ToString();
}
</script>