Difference between DropDownList.SelectedItem.Value

2019-07-28 04:15发布

问题:

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

回答1:

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.



回答2:

selectedValue retrns the order no of listitem of dropdown and nothing is selected then it returns "" and Selecteditem.text return text of selected item and selecteditem.value also returns order no but if not selected then throw an error