开发者

'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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜