List controls deriving from ListControl
, such as DropDownList
, ListBox
or RadioButtonList
, are populated by a list of ListItem
s. A ListItem
has a Value
and a Text
property.
ListControl
offers the following methods to access the currently selected item:
ListControl.SelectedItem
returns the currently selectedListItem
,ListControl.SelectedValue
returns theValue
property of the currently selectedListItem
.
Now, the interesting thing is:
ListControl.Text
returns exactly the same value asListControl.SelectedValue
. It does not returnSelectedItem.Text
, as one might expect.
This is by design:
ListControl.Text Property
Gets or sets the SelectedValue property of the ListControl control.
[...]
Remarks
The Text property gets and sets the same value that the SelectedValue property does.
This seems counter-intuitive and confuses people. My question is: Why was it done this way? I can imagine that providing a Text
property is necessary for implementing the ITextControl
interface, but why on earth would you choose to have it return the Value
of the ListItem rather than the Text
?