我正在使用Vb.net在asp.net网站上工作,并且我具有一个具有autopostback = true的下拉列表,并且在更改项目时我需要获取选定的值,或者要获取引发selectedindexchanged事件的项目。
任何帮助请..
最佳答案
在即。您的Page_Load集
this.ComboBox1.SelectedIndexChanged += new System.EventHandler(ComboBox1_SelectedIndexChanged);
然后像这样编写事件处理程序:
private void ComboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
ComboBox comboBox = (ComboBox) sender;
string selected = (string) comboBox.SelectedItem;
}
确保在设置组合框默认值之前在Page_Load中编写了此代码,否则最终将始终将其作为选定项:
if (Page.IsPostBack)
return;