Selectedindexchanged 事件中的下拉列表选定值

发布于 2025-01-07 07:36:07 字数 139 浏览 4 评论 0原文

我正在使用 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 ..

any help please..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

呢古 2025-01-14 07:36:07

在即。你的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;

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;
}

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;
通知家属抬走 2025-01-14 07:36:07

试试这个:

    protected void list_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList list = (DropDownList)sender;
        string value = (string)list.SelectedValue;
    }

try this:

    protected void list_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList list = (DropDownList)sender;
        string value = (string)list.SelectedValue;
    }
放赐 2025-01-14 07:36:07

如果项目是字典:

string value = ((KeyValuePair<string, string>)combobox.SelectedItem).Key;

If item is a Dictionary:

string value = ((KeyValuePair<string, string>)combobox.SelectedItem).Key;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文