Assume that I have a dropdownlist with 2 items and, by default, the first item is selected. If I select the click the first item in the dropdownlist, is there a way I can get the SelectedIndexChanged() event to still fire?
I thought I could do it by setting the SelectedIndex of the dropdownlist to -1, but that didn’t work, because it does not display the currently selected value, so it is misleading.
An issue I have on this is that the dropdownlist 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 dropdownlist like:
Sort Numbers (Asc)
Sort Numbers (Desc)
Sort Alphabet (Asc)
Sort Alphabet (Desc)
Note: This is based on the updated content of the question.
Let’s say you have one drop down list and one listbox (dropdownlist1 and listbox1)
You can set up your initial drop down list in your page_load event as such:
Then on your dropdownlist1.selectedindexchanged event you would handle it as such:
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.