DropDownList 不正确的 SelectedIndex

DropDownList Incorrect SelectedIndex

DropDownList 控件 return 输入了错误的项目。

我的代码在 DropDownList.SelectedValue = -1 时使用 SelectedItem 执行特定操作。

测试代码时,我在 index = 2 处选择项目 A。结果DropDownList.SelectedItem = "A"。目前还不错。

但我在 index = 3 选择了项目 B。结果DropDownList.SelectedItem = "A"。根据调试器,两种情况下都是 DropDownList.SelectedIndex = 2

是什么原因导致 SelectedIndex 始终采用相同的值?

注意:当我选择项目 CZ 时,它们 return 正确的 SelectedTextSelectedIndex

if(Int32.Parse(dropdown.SelectedValue).Equals(-1))
{
    // Do something with the selected item
    DoThis(dropdown.SelectedItem.ToString());
}

当 DropDownList 中的多个项目具有相同的值时,选择其中任何一个都会像选择具有该值的第一个项目一样。您应该修改重复的值,使每个值都是唯一的。