kor*_*wan 1 c# combobox isnullorempty
我试图将一个combobox.selectedValue设置为一个有效的字符串,但是当它的nullorempty错误输出时.我尝试了以下代码无济于事:
if (string.IsNullOrEmpty(docRelComboBox.SelectedValue.ToString()))
{
document = "other";
}
else
{
document = docRelComboBox.SelectedValue.ToString();
}
Run Code Online (Sandbox Code Playgroud)
组合框是数据绑定的,但理论上它在某些情况下可能是无空的,我需要能够在那些时间传递其他值.任何帮助都会很棒.
你可能需要:
if ((docRelComboBox.SelectedValue==null) || string.IsNullOrEmpty(docRelComboBox.SelectedValue.ToString()))
Run Code Online (Sandbox Code Playgroud)
因为SelectedValue它本身可能是空的.