dropdownlist 显示日期
来源:互联网 发布:通过mac地址发送消息 编辑:程序博客网 时间:2024/05/16 05:26
dropdownlist1代表年 autopostback=true
dropdownlist2代表月 autopostback=true
dropdownlist3代表日
protected void Page_Load(object sender, EventArgs e)
...{
string s = Request.QueryString["id"];
Response.Write(Server.UrlDecode(s));
DateTime tnow = DateTime.Now;
ArrayList years = new ArrayList();
ArrayList months = new ArrayList();
int i;
for (i = 1991; i >= 1958; i--)
...{
years.Add(i);
}
for (i = 1; i <= 12; i++)
...{
months.Add(i);
}
if (!IsPostBack)
...{
DropDownList1.DataSource = years;
DropDownList1.SelectedValue =years[8].ToString();
DropDownList1.DataBind();
DropDownList2.DataSource = months;
DropDownList2.SelectedValue = tnow.Month.ToString();
DropDownList2.DataBind();
int year, month;
Int32.TryParse(tnow.Year.ToString(), out year);
Int32.TryParse(tnow.Month.ToString(), out month);
binddropdownlist3(year, month);
DropDownList3.SelectedValue = tnow.Day.ToString();
}
}
protected bool checkLeap(int year)
...{
if ((year % 4 != 0) && (year % 100 != 0) || (year % 400 == 0))
...{
return true;
}
else
...{
return false;
}
}
protected void binddropdownlist3(int year, int month)
...{
int i;
ArrayList days = new ArrayList();
switch (month)
...{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
for (i = 1; i <= 31; i++)
...{
days.Add(i);
}
break;
case 2:
if (checkLeap(year))
...{
for (i = 1; i <= 29; i++)
...{
days.Add(i);
}
}
else
...{
for (i = 1; i <= 28; i++)
...{
days.Add(i);
}
}
break;
case 4:
case 6:
case 9:
case 11:
for (i = 1; i <= 30; i++)
...{
days.Add(i);
}
break;
}
DropDownList3.DataSource = days;
DropDownList3.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
...{
int year, month;
Int32.TryParse(DropDownList1.SelectedValue.ToString(), out year);
Int32.TryParse(DropDownList2.SelectedValue.ToString(),out month);
binddropdownlist3(year, month);
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
...{
int year, month;
Int32.TryParse(DropDownList1.SelectedValue.ToString(),out year);
Int32.TryParse(DropDownList2.SelectedValue.ToString(),out month);
binddropdownlist3(year, month);
}
但是这种做法会刷新页面,不是很好!
- dropdownlist 显示日期
- dropDownList显示日期格式的数据
- DropDownList的联机显示
- dropdownlist 显示指定选项
- DropDownList 下拉列表显示
- DropDownList中显示树状数据
- DIV DataGrid DropDownList 详细显示
- DropDownList实现树形结构显示
- (转)dropdownlist分级显示(改)
- 在DropDownList中显示树
- dropDownList里显示加入空格
- DropDownList绑定后显示默认值
- 关于dropdownlist逐级显示单位
- DropDownList控件显示年份示例
- DropDownList分级绑定显示数据
- C#中DropDownList显示默认值
- 显示日期..........
- 日期显示
- 菜鸟进阶学堂(三):认识液晶显示器
- VC常用数据类型使用转换摘录2
- Spring管理事务的若干配置形式
- JSF入门笔记三(国际化)
- 在制定位置截取字符并加入自定义符号。默认加入....及当为NULL时转成""
- dropdownlist 显示日期
- RIA 应该通过 html 5 实现
- 死锁(deadlock)
- SOA从复合应用入手
- 怎么实现点击textbox后textbox里用于提示的文字消失
- accesskey
- 关于spring声明式事务管理异常处理
- DataGrid点击删除按钮弹出确认对话框一个好办法
- 上帝安排的任务-细节决定一切