控制listbox只能单选
控制listbox只能单选,我的代码如下:
if (RadioButtonList1.SelectedItem.Value == "1 ")
this.ListBox1.SelectionMode = ListSelectionMode.Single;
else
this.ListBox1.SelectionMode = ListSelectionMode.Multiple;
运行起来仍然可以多选,并有错误提示:
当 SelectionMode 为 Single 时,不能选择多项。
怎么解决,有做过的朋友吗
------解决方案--------------------if (RadioButtonList1.SelectedItem.Value == "1 ") {
//this.ListBox1.SelectedIndex = -1;
// OR
foreach(ListItem item in this.ListBox1.Items) item.Selected = false;
this.ListBox1.SelectionMode = ListSelectionMode.Single;
}
else
this.ListBox1.SelectionMode = ListSelectionMode.Multiple;
------解决方案--------------------先全部不选,然后设置选择模式
------解决方案--------------------mark