如何将默认值添加到RadComboBox?

时间:2011-01-13 15:07:23

标签: c# asp.net telerik

我正在尝试向我的WCF服务添加一个额外的项目。这是我的代码。我有一个代码从数据库中获取值。我想将默认项“All”添加到数组中。这是我的WCF代码。

RadComboBoxData result = new RadComboBoxData();
var listView = new listTypedView();

//In case the user typed something - filter the result set
string text = String.Concat("%", context.Text, "%");
if (!String.IsNullOrEmpty(text))
{
    using (DataAccessAdapter adapter = LLBLGenAdapterUtility.GetAdapter())
    {
        RelationPredicateBucket filter = new RelationPredicateBucket();
        filter.PredicateExpression.Add(ViewNameFields.Name % text);
        adapter.FetchTypedView(personView.GetFieldsInfo(), listView, filter, 0, null, false);
    }
}

var allList = from n in listView
                  select new RadComboBoxItemData
                  {
                      Text = n.pName,
                      Value = n.Id.ToString()
                  };
result.Items = allList.ToArray();

2 个答案:

答案 0 :(得分:5)

你在找这样的东西吗?

result.Items = (new List<RadComboBoxItemData> 
  { 
    new RadComboBoxItemData { Text = "All", Value = "" }
  }).Concat(allList).ToArray();

答案 1 :(得分:2)

德堡,我讨厌一线回答。调试会带来严重的痛苦。我已经对Ladislav的答案提出了异议,但这里的格式很好

var allList = from n in listView
                          select new RadComboBoxItemData
                          {
                              Text = n.pName,
                              Value = n.Id.ToString()
                          };
List<RadComboBoxItemData> listOfItems = new List<RadComboBoxItemData>();
listOfItems.Concat(allList);

RadComboBoxItemData defaultItem = new RadComboBoxItemData();
defaultItem.Text = "All";
defaultItem.Value = string.empty;
listOfItems.Insert(0, defaultItem);

result.Items = listOfItems.ToArray();