如果项目在下拉列表中已选择SelectedIndexChanged事件不火? [英] SelectedIndexChanged event does not fire if Item is already selected in dropdown?

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

问题描述

假设我有2项,默认情况下下拉,第一项被选中。如果我在下拉列表中选择点击的第一个项目,是有办法,我可以得到SelectedIndexChanged事件仍火?

Assume that I have a dropdown with 2 items and by default, the first item is selected. If I select the click the first item in the dropdown, is there a way I can get the selectedIndexChanged event to still fire?

我可以用下拉的selectedIndex设置为-1,例如做呢?

Can I do it by setting the SelectedIndex of the Dropdown to -1, for example?

好了,没有工作,洛尔,因为它不会显示当前选择的值,所以它是一种误导。

Well that didn't work, lol, because it does not display the currently selected value, so it is misleading.

这是问题,我对这个是下拉被用于排序。我有分拣半的工作中,如果我选择第二项,它会按升序排序的例子,但如果我想在现在使用的第二项降序排序,我不得不选择其他项目,然后回去第二个项目。

An issue I have on this is that the dropdown is used for sorting. I have the sorting semi-working in that if I select the second item, it will sort in ascending order for example, but if I want to sort in descending order now using the second item, i have to select another item and then go back to the second item.

即使我添加选择依据...我认为要排序的最佳解决方案是只是像的下拉更多的项目:

Even if I add a Select By... I think the best solution to sorting is to just have more items in the dropdown like:

排序号(ASC)

排序号(说明)

字母排序(ASC)

字母排序(DESC)

谢谢,
XaiSoft

Thanks, XaiSoft

推荐答案

请注意:这是基于问题的更新内容。

Note: This is based on the updated content of the question.

假设你有一个下拉列表和一个列表框(dropdownlist1和ListBox1中)

Let's say you have one drop down list and one listbox (dropdownlist1 and listbox1)

您可以设置您最初的下拉列表中的Page_Load事件,例如:

You can set up your initial drop down list in your page_load event as such:

dropdownlist1.items.insert(0, "----Select Sort Method----")
dropdownlist1.items.insert(1, new ListItem("Alphabetic Ascending", "AlphaAsc"))
dropdownlist1.items.insert(2, new ListItem("Alphabetic Descending", "AlphaDesc"))
dropdownlist1.items.insert(3, new ListItem("Numeric Ascending", "NumAsc"))
dropdownlist1.items.insert(4, new ListItem("Numeric Descending", "NumDesc"))
dropdownlist1.selectedindex = 0

然后在你的dropdownlist1.selectedindexchanged事件你会处理它这样:

Then on your dropdownlist1.selectedindexchanged event you would handle it as such:

if dropdownlist1.selectedindex <> 0 then
   select case dropdownlist1.selectedvalue
       case "AlphaAsc"
            Insert Code to Sort ListBox1 Alphabetically in ascending order
       case "AlphaDesc"
            Insert Code to sort ListBox1 Alphabetically in descending order
       case "NumAsc"
            Insert code to sort ListBox1 Numerically in ascending order
       case "NumDesc"
            Insert code to sort ListBox1 Numerically in descending order
   end select
end if

请注意:你会希望确保,如果你想排序时在一个项目的选择立即发生的dropdownlist1的AutoPostBack属性设置为true

Note: You would want to make sure that your dropdownlist1's AutoPostBack property is set to true if you want the sorting to happen immediately upon selection of an item.

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

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