我正在使用:
if (RadioButtonList_VolunteerType.SelectedItem != null)
或者这样怎么样:
if (RadioButtonList_VolunteerType.Index >= 0)
或者考虑使用(根据Andrew Hare的回答):if (RadioButtonList_VolunteerType.Index > -1)
对于那些可能会阅读这个问题的人,以下不是有效的方法。正如Keltex指出的那样,所选值可能是一个空字符串。
if (string.IsNullOrEmpty(RadioButtonList_VolunteerType.SelectedValue))