我正在尝试将combobox.selectedValue设置为可以工作的字符串,但是当其为nullorempty时,它会出错。我尝试了以下代码无济于事:

        if (string.IsNullOrEmpty(docRelComboBox.SelectedValue.ToString()))
        {
            document = "other";
        }

        else
        {
            document = docRelComboBox.SelectedValue.ToString();
        }


组合框是数据绑定的,但理论上在某些情况下它可以为null或空,因此我需要能够在那些时候传递其他值。任何帮助都会很棒。

最佳答案

您可能需要:

if ((docRelComboBox.SelectedValue==null) || string.IsNullOrEmpty(docRelComboBox.SelectedValue.ToString()))


由于SelectedValue本身可能为null。

关于c# - IsNullorEmpty组合框.selected值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5916508/

10-10 21:40