求助!ASP.NET 实现年月日联动问题
年和月不需要联动,只要月和日联动就OK了。在月的SelectedIndexChanged事件里根据年和月来动态的添加日的数据。选择月后,日没有反应
<asp:DropDownList ID="birthYear" runat="server"></asp:DropDownList>年
<asp:DropDownList ID="birthMonth" runat="server" OnSelectedIndexChanged="birthMonth_SelectedIndexChanged">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>9</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>11</asp:ListItem>
<asp:ListItem>12</asp:ListItem>
</asp:DropDownList> 月 <asp:DropDownList ID="birthDay" runat="server">
protected void birthMonth_SelectedIndexChanged(object sender, EventArgs e)
{
birthDay.Items.Clear();
switch (birthMonth.SelectedValue)
{
case "1":
case "3":
case "5":
case "7":
case "8":
case "10":
case "12":
for (int i = 1; i <= 31; i++)
{
birthDay.Items.Add(new ListItem(Convert.ToString(i), Convert.ToString(i)));
}
break;
case "4":
case "6":
case "9":
case "11":
for (int i = 1; i <= 30; i++)
{
birthDay.Items.Add(new ListItem(Convert.ToString(i), Convert.ToString(i)));
}
break;
case "2":
if ((Convert.ToInt32(birthYear.SelectedValue) % 4 == 0) || (Convert.ToInt32(birthYear.SelectedValue) % 100 == 0))
{
for (int i = 1; i <= 29; i++)
{
birthDay.Items.Add(new ListItem(Convert.ToString(i), Convert.ToString(i)));
};
}
else
{
for (int i = 1; i <= 28; i++)
{
birthDay.Items.Add(new ListItem(Convert.ToString(i), Convert.ToString(i)));
};
}
break;
}
}