public virtual ListItem SelectedItem {
get {
int selectedIndex = this.SelectedIndex;
if (selectedIndex >= 0) {
return this.Items[selectedIndex];
}
return null;
}
}
public virtual string SelectedValue {
get {
int selectedIndex = this.SelectedIndex;
if (selectedIndex >= 0) {
return this.Items[selectedIndex].Value;
}
return string.Empty;
}
}
在没有选定任何项的情况下,SelectedValue默认值是string.Empty,而SelectedItem默认值是null(通过SelectedItem.Value可能发生异常)
DropDownList.SelectedValue
The value of the selected item in the list control. The default is an empty string ("").
DropDownList.SelectedItem.Value
A ListItem that represents the lowest indexed item selected from the list control. The default is nullNothingnullptra null reference (Nothing in Visual Basic).
就值来说应该是一样的。不过如果DropDownList.SelectedItem为null的话,后者肯定会报错。
我认为是一样的
值是一样的