Difference between DropDownList.SelectedItem.Value And DropDownList.SelectedValue (ASP.NET)

Wassim AZIRAR picture Wassim AZIRAR · May 31, 2010 · Viewed 17.5k times · Source

I'm getting an error when SelctedIndexChanged, When the value change he gives me the previous selected value and not the new selected value.

What's the problem here.

And what's the difference between

DropDownList.SelectedItem.Value 
DropDownList.SelectedValue

Answer

Maze picture Maze · Feb 16, 2011

SelectedValues returns the Value of the selecteditem or "" if there is none.

SelectedItem returns the selected item. SelectedItem.Value return the .Value of the SelectedItem. SelectedItem.Value will throw an error if there is no selected item, because SelectedItem will return null, and .Value of null will throw the error.