我有一个类,其中有FreeDressingItems,FreeToppingItems,FreeInstructionItems的集合
I have class where i have the collection of FreeDressingItems, FreeToppingItems, FreeInstructionItems
都填充selectedCustomization我在此类public string Items { get { return GetAllItems(); } }
that is like this each of which fill selectedCustomization i have another property in this class public string Items { get { return GetAllItems(); } }
我要填写,以便保留相同类别类型的所有分类名称,以便我可以轻松地将其绑定到网格并以逗号分隔的形式显示其所有值.
that i want to fill so that it keeps the all catetoryname for the same category type so that i can bind it to grid easily and display all its value in comma separated form.
我有以下代码可以帮助我如何实现这一目标.
i have following code could somebody help me how can i acineve this.
public class selectedCustomization { public CategoryType TypeName { get; set; } public string CategoryName { get; set; } public string ItemName { get; set; } public int SourceID { get; set; } public string Items { get { return GetAllItems(); } } private string GetAllItems() { switch (TypeName) { case CategoryType.Dressing: { cFreeCustomization cfreeCust = new cFreeCustomization(); break; } case CategoryType.Topping: break; case CategoryType.SpecialInstruction: break; } } }这是另一个类cFreeCustomization
this is another class cFreeCustomization
public List<selectedCustomization> SelectedItems { get { libDBDataContext cn = new libDBDataContext(); List<selectedCustomization> lst = new List<selectedCustomization>(); lst.AddRange( (from xx in this.FreeDressingItems select new selectedCustomization() { TypeName = CategoryType.Dressing, CategoryName = xx.DressingInfo.CatName, ItemName = xx.DressingInfo.Description } ).ToList() ); lst.AddRange( (from xx in this.FreeToppingItems select new selectedCustomization() { TypeName = CategoryType.Topping, CategoryName = xx.ToppingInfo.CatName, ItemName = xx.ToppingInfo.Description } ).ToList() ); lst.AddRange( (from xx in this.FreeInstructionItems select new selectedCustomization() { TypeName = CategoryType.SpecialInstruction, CategoryName = xx.InstructionInfo.CatName, ItemName = xx.InstructionInfo.Description } ).ToList() ); return lst; } }如何以逗号分隔形式设置selectedCustomization的关系?
How can i make tiems of selectedCustomization in comma separated form?
推荐答案我相信 GetAllItems 方法应如下所示:
I believe the method GetAllItems should be like below:
private string GetAllItems() { cFreeCustomization cfreeCust = new cFreeCustomization(); var ls = cfreeCust.SelectedItems.FindAll(I => I.TypeName == this.TypeName); return string.Join(",", ls.Select(I => I.CategoryName).ToArray()); }这将解决您的问题.
更多推荐
我如何在另一个班级中填写一个班级的财产?
发布评论