Does the SelectedIndexChanged event not fire if the item is already selected in the drop-down list?

Suppose I have a drop-down list with two items, and the first item is selected by default. If I select a click on the first item in the drop-down list, is there a way I can get the selectedIndexChanged event to still fire?

Can I do this by setting, for example, SelectedIndex in Dropdown to -1?

Well, this did not work because it does not display the current selected value, therefore it is misleading.

The problem is that the dropdown menu is used for sorting. I have a sort, consisting in the fact that if I select the second element, it will be sorted in ascending order, for example, but if I want to sort in descending order now using the second element, I have to select another element and then go back to the second paragraph.

Even if I add Select By ... I think the best solution for sorting is to simply have more items in the drop-down list, for example:

Sorting numbers (Asc)

Sort Numbers (Desc)

Alphabet Sort (Asc)

Alphabet Sort (Desc)

Thanks, XaiSoft

+3
source share
4 answers

Note. This is based on updated question content.

, (dropdownlist1 listbox1)

page_load :

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 :

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 

. , dropPaintBack dropdownlist1 true, , .

+1

: , .

, ", ..." .

+6

, - " - "? , , , , selectedindexchanged .

- :

DropDownList1.Items.Insert(0, "Select an Item")
         DropDownList1.SelectedIndex = 0

, .

:

var a = new AddressesBLL();
        cmbPersonAddress1.DataSource = a.GetAddresses();
        cmbPersonAddress1.DataBind();


        //Set the default text to the below text but don't let it be part of the selections on the drop down.
        cmbPersonAddress1.Text = "Please select an existing address...";

", ..." . ddl, , indexchanged .

+2
source

As before, add the first element of text to direct the user to select an element from the list.

If you bind anchor elements, you want to insert the element later.

Dropdownlist1.datasource = whatever
Dropdownlist1.datatextfield = "Something"
dropdownlist1.datavaluefield = "ValueField"
dropdownlist1.databind
dropdownlist1.items.insert(0, "----Select Something!----")
dropdownlist1.selectedindex = 0

and then in your SelectedIndexChangedevent, you can prevent the action on the first element by wrapping all your code in an if statement:

If DropDownList1.SelectedIndex <> 0 then
   Do Your Work
End If
+2
source

Source: https://habr.com/ru/post/1703105/


All Articles