Dictionary
Dictionary<string, ExtendColGroup> extendcolgroup = new Dictionary<string, ExtendColGroup>(); foreach (var item in cols) { if (extendcolgroup.ContainsKey(item.ExtendColGroupName)) { ExtendColGroup colItem = extendcolgroup[item.ExtendColGroupName]; colItem.Count++; colItem.Items.Add(item); } else { var colItem = new ExtendColGroup() { Items = new List<V_Sys_Customer>(), ExtendColGroupName = item.ExtendColGroupName }; colItem.Count = 1; colItem.Items.Add(item); extendcolgroup.Add(item.ExtendColGroupName, colItem); } } ViewData["extendcolgroup"] = extendcolgroup; cols.Add(new V_Sys_Customer() { ExtendColName = "afas", ExtendColValue = "sdfas" }); cols.Add(new V_Sys_Customer() { ExtendColName = "sdf", ExtendColValue = "asdfadsf" }); cols.Add(new V_Sys_Customer() { ExtendColName = "trge", ExtendColValue = "asdfdasf" }); cols.Add(new V_Sys_Customer() { ExtendColName = "34", ExtendColValue = "asdfasdf" }); cols.Add(new V_Sys_Customer() { ExtendColName = "asdas爱的", ExtendColValue = "asdfasdf" }); ViewData["cols"] = cols;