我有一个包含多个值的下拉列表,我从数据库表中提取值。这工作正常。我试图插入一个新的ListItem。我可以使用单个值添加New ListItem。例如:
ListTest.Items.Insert(0, new ListItem("Test", "THIS"));
这给出了“THIS”的值,但我需要它具有“This and That and Something Else”的值。因此,如果选择“TEST”,它将检查表格中的3个不同项目。这甚至可能吗?
答案 0 :(得分:0)
这是扩展方法的一种方法。这假设您要对所选值与要查找的值之间的关系进行硬编码。
public string[] GetImpliedSelectedValues(this listBox)
{
switch case listBox.SelectedValue)
{
case "this_1_thru_3":
return new string[] {"this1", "this2", "this3"};
break;
case "this_4_and_5":
return new string[] {"this4", "this5"};
break;
default:
return new string[] {"nothing"};
}
}
然后在你的代码隐藏中,只需使用
var valuesSelected = MyListBox.GetImpliedSelectedValues();
foreach (var v in valuesSelected)
{
DoSomething(v);
}
答案 1 :(得分:-1)
我不明白你的问题......我会试试 你可以使用例如“This_That”并执行拆分