求asp.net 2.0下拉框 联动 后台原码例子

来源:百度知道 编辑:UC知道 时间:2024/05/25 02:41:28
越详细越好!重重有赏!!

aspx页面上有三个DropDownList控件,后台数据库建表,年月日。
DropDownList1 表示年,DropDownList2表示月,DropDownList3表示天;
注意用将这三个DropDownList控件的AutoPostBack属性设为True。

用户可以方便地选择年月日,并且每月的日期会随着用户选择不同的年,月而发生相应的变化

其后台cs文件代码如下:

private void Page_Load(object sender, System.EventArgs e)
{
DateTime tnow=DateTime.Now;//现在时间
ArrayList AlYear=new ArrayList();
int i;
for(i=2002;i<=2010;i++)
AlYear.Add(i);
ArrayList AlMonth=new ArrayList();
for(i=1;i<=12;i++)
AlMonth.Add(i);
if(!this.IsPostBack )
{
DropDownList1.DataSource=AlYear;
DropDownList1.DataBind();//绑定年
//选择当前年
DropDownList1.SelectedValue=tnow.Year.ToString();
DropDownList2.DataSource=AlMonth;
DropDownList2.DataBind();//绑定月
//选择当前月
DropDownList2.SelectedValue=tnow.Month.ToString();
int year,month;
year=Int32.Parse(DropDownList1.SelectedValue);