开发者

How can I add default value to a RadComboBox?

I am trying to add an extra item to my WCF service. Here is my code. I have a code which gets the values from the database. I would like to add default item 'All' to array. Here is my WCF code.

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

//In case the user typed something - filter the resu开发者_如何学运维lt 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();


Are you looking for something like this?

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


Durg, I hate all-in-one-line answers. Makes for a serious pain to debug. I've upvoted Ladislav's answer, but here it is nicely formatted

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜