读书人

DropDownList,该怎么处理

发布时间: 2013-01-20 10:22:41 作者: rapoo

DropDownList

 if (DroDL_BeginYear.SelectedItem.ToString() == "2011")
{
DroDL_BeginMonth.Items.Add(new ListItem("4", "4"));
DroDL_BeginMonth.Items.Add(new ListItem("5", "5"));
DroDL_BeginMonth.Items.Add(new ListItem("6", "6"));
}
else if (DroDL_BeginYear.SelectedItem.ToString() == "2013")
{
DroDL_BeginMonth.Items.Add(new ListItem("1", "1"));
DroDL_BeginMonth.Items.Add(new ListItem("2", "2"));
DroDL_BeginMonth.Items.Add(new ListItem("3", "3"));
DroDL_BeginMonth.Items.Add(new ListItem("4", "4"));
DroDL_BeginMonth.Items.Add(new ListItem("5", "5"));
DroDL_BeginMonth.Items.Add(new ListItem("6", "6"));
DroDL_BeginMonth.Items.Add(new ListItem("7", "7"));
DroDL_BeginMonth.Items.Add(new ListItem("8", "8"));
DroDL_BeginMonth.Items.Add(new ListItem("9", "9"));
}


这应该在哪里写,效果是当DropDownList控件BeginYear为2011时,别一个控件BeginMonth只有3,4,5可以选,当为2013时,就有123456789可以选!
最好可以变灰,谢谢!
[解决办法]
在page_load 中写 将BeginYear控件的AutoPostBack 设为true
[解决办法]
SelectedIndexChanged事件
[解决办法]
SelectedIndexChanged事件中写,别忘记每次删除DroDL_BeginMonth.Items.Clear(),还有dropdownlist的AutoPostBack设置为true

读书人网 >C#

热点推荐