我正在使用 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;
关于asp.net - Selectedindexchanged 事件中的下拉列表选定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9371187/