我正在尝试向我的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();
答案 0 :(得分:5)
你在找这样的东西吗?
result.Items = (new List<RadComboBoxItemData>
{
new RadComboBoxItemData { Text = "All", Value = "" }
}).Concat(allList).ToArray();
答案 1 :(得分:2)
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();