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

江枫思渺然 提交于 2019-12-11 05:53:41

问题


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



来源:https://stackoverflow.com/questions/2944036/difference-between-dropdownlist-selecteditem-value-and-dropdownlist-selectedvalu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!