组合框检查项目为单个字符串

时间:2013-05-23 09:44:24

标签: c# asp.net string combobox telerik

这是我的代码,

string _towns = String.Join(",", 
(usercontrol.FindControl("comboTown") as RadComboBox).CheckedItems);

'comboTown'的值为

Town1
Town2
Town3
Town4

如果我选中了Town2Town3,我希望得到以逗号分隔的单个字符串Town2,Town3。但我的代码返回Telerik.Web.UI.RadComboBoxItem,Telerik.Web.UI.RadComboBoxItem。如何才能获得已检查项目的值?

3 个答案:

答案 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+",");
}