| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 470 人关注过本帖
标题:奇怪问题
取消只看楼主 加入收藏
meteor86
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2008-4-14
收藏
 问题点数:0 回复次数:1 
奇怪问题
我用3个DropDownList分别显示,年,月,日.   假如我用一个按钮让它显示出来,怎么一点击,无论,日,选的是什么数字,最后都显示 1 呢?

注:前两个DropDownList的autopostback属性为true.
   年和月的DropDownList的item我是自己加上去的,日的是根据年月绑定的.呜呜.

如下:
    protected void Page_Load(object sender, EventArgs e)
    {
        int year = Convert.ToInt32(this.yearlist.SelectedItem.Text);
        int month = Convert.ToInt32(this.monthlist.SelectedItem.Text);

        int day = dayCount(year, month);
        this.daylist.Items.Clear();



        for (int i = 1; i <= day; i++)
        {
            this.daylist.Items.Add(i.ToString());
        }
    }
    // 判断是否是闰年
    private bool isLeapYear(int year)
    {
        return (((year % 4 == 0) && (year % 100 != 0)) || ((year % 100 == 0) && (year % 400 == 0)));
    }

    // 根据年份和月份计算该月的日数
    private int dayCount(int year, int month)
    {
        int day = 0;
        if (isLeapYear(year))
        {
            switch (month)
            {
                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                case 12:
                    day = 31;
                    break;
                case 4:
                case 6:
                case 9:
                case 11:
                    day = 30;
                    break;
                case 2:
                    day = 29;
                    break;
                default:
                    day = -1;
                    break;
            }

            return day;
        }
        else
        {
            switch (month)
            {
                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                case 12:
                    day = 31;
                    break;
                case 4:
                case 6:
                case 9:
                case 11:
                    day = 30;
                    break;
                case 2:
                    day = 28;
                    break;
                default:
                    day = -1;
                    break;
            }

            return day;
        }
    }
2008-04-15 20:35
meteor86
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2008-4-14
收藏
得分:0 
哦,呵呵,谢你啦!
2008-04-15 22:10
快速回复:奇怪问题
数据加载中...
 
   



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

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