'Not selected' property value on drop down box selected value
I have an ASP.NET site (either .NET 2.0 or 3.5), and I want to get the selected item of two drop down boxes (call them a and b). B is updated with appropriate values depending on what is selected开发者_开发问答 for A.
However, the following code:
string val = dd1.SelectedItem.Text;
Returns a value of "not selected". Why is this?
Thanks
The only way this could happen is if you have "not selected" set as either the Text property of your selected item, or if Text is null then the Value property will be returned.
From MSDN's documentation on ListItem (which is what SelectedItem inherits from):
If the Text property contains null, the get accessor returns the value of the Value property. If the Value property, in turn, contains null, String.Empty is returned.
精彩评论