Selected Dropdownlist value in Selectedindexchanged event

I am working on an asp.net website with Vb.net and I have a drop-down list with autopostback = true and I need to get the selected value when I change the item, or I want to get the item that fires the selectedexexchanged event ..

any help please.

+6
source share
3 answers

Including your Page_Load set

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

Then write an event handler as follows:

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

Make sure you write this in your Page_Load before setting the default value for combobox, otherwise you will always be the selected item:

 if (Page.IsPostBack) return; 
+6
source

try the following:

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

If the item is a dictionary:

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

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


All Articles