这是我的代码,
string _towns = String.Join(",",
(usercontrol.FindControl("comboTown") as RadComboBox).CheckedItems);
'comboTown'的值为
Town1
Town2
Town3
Town4
如果我选中了Town2
和Town3
,我希望得到以逗号分隔的单个字符串Town2,Town3
。但我的代码返回Telerik.Web.UI.RadComboBoxItem,Telerik.Web.UI.RadComboBoxItem
。如何才能获得已检查项目的值?
答案 0 :(得分:5)
您必须访问Text
RadComboBoxItem
var selectedTowns = (usercontrol.FindControl("comboTown") as RadComboBox)
.Items.Where(i => i.Checked)
.Select(i => i.Text)
.ToArray();
string _towns = String.Join(",", selectedTowns);
答案 1 :(得分:2)
string _towns = String.Join(",",(usercontrol.FindControl("comboTown") as RadComboBox).Items
.Where(i => i.Checked)
.Select(i => i.Text).ToList());
OR
string _towns = String.Join(",",(usercontrol.FindControl("comboTown") as RadComboBox).CheckedItems).Select(i => i.Text).ToList());
答案 2 :(得分:0)
StringBuilder str= new StringBuilder();
//Register Combo Selected Index Changed Event
Combo_OnSelectedIndexChange(abc,abc) {
{
str.append(ComboBox1.SelectedItem.Text+",");
}