Amr Elnashar Amr Elnashar - 1 year ago 101
ASP.NET (C#) Question

Dropdownlist selected value at Selectedindexchanged event

I'm working on website with 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..

Answer Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download