在SelectedIndexchanged事件中下拉列表选择的值 [英] Dropdownlist selected value at Selectedindexchanged event

查看:324
本文介绍了在SelectedIndexchanged事件中下拉列表选择的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Vb.net在asp.net网站上工作,并且具有一个autopostback = true的下拉列表,并且在更改项目时我需要获取选定的值,或者我希望获取引发selectedindexchanged事件的项目..

I'm working on asp.net website with Vb.net and I have a dropdownlist with autopostback = true and I need to get the selected value when I change the item or I want to get the item which fires the selectedindexchanged event ..

请帮忙.

推荐答案

在ie中.您的Page_Load集

In ie. your Page_Load set

this.ComboBox1.SelectedIndexChanged += new System.EventHandler(ComboBox1_SelectedIndexChanged);

然后像这样编写事件处理程序:

Then write the event handler like this:

private void ComboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
  ComboBox comboBox = (ComboBox) sender;
  string selected = (string) comboBox.SelectedItem;
}

确保在设置组合框默认值之前在Page_Load中编写此代码,否则最终将始终将其作为选定项:

Make sure that in your Page_Load you write this before setting the combobox default value or you will end up with this always being the selected item:

if (Page.IsPostBack)
  return;

这篇关于在SelectedIndexchanged事件中下拉列表选择的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆