| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 947 人关注过本帖
标题:ASP.NET 年月日实现联动
取消只看楼主 加入收藏
zhuwj
Rank: 2
来 自:江苏
等 级:论坛游民
威 望:1
帖 子:63
专家分:58
注 册:2010-11-18
结帖率:64.71%
收藏
 问题点数:0 回复次数:0 
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>&nbsp; 月&nbsp;<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;
            }
        }
搜索更多相关主题的帖子: 年月日 
2011-04-23 10:58
快速回复:ASP.NET 年月日实现联动
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011612 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved