我有一个如下列表:
public static List<Record> initRecords() {
var list = new List<Record>();
list.Add(new Record {UserID = "aaa", FieldName = "First Name", FieldValue = "Joey"});
list.Add(new Record {UserID = "aaa", FieldName = "Last Name", FieldValue = "Williams"});
list.Add(new Record {UserID = "aaa", FieldName = "Company", FieldValue = "Microsoft"});
list.Add(new Record {UserID = "bbbb", FieldName = "First Name", FieldValue = "Larry"});
list.Add(new Record {UserID = "bbbb", FieldName = "Last Name", FieldValue = "Johnson"});
list.Add(new Record {UserID = "bbbb", FieldName = "Company", FieldValue = "Knicks"});
list.Add(new Record {UserID = "bbbb", FieldName = "Comment", FieldValue = "4-1"});
list.Add(new Record {UserID = "ccc", FieldName = "First Name", FieldValue = "Allen"});
list.Add(new Record {UserID = "ccc", FieldName = "Last Name", FieldValue = "Houston"});
list.Add(new Record {UserID = "ccc", FieldName = "Company", FieldValue = "Lala"});
return list;
}
我使用LINQ将它们按用户ID分组到三个组,如您所见,每个组的记录数不同
var records = list.GroupBy(u => u.UserID).Select(grp => grp.ToList()).ToList();
现在一切都很好,但是我需要一些指导来将这个分组列表构建到数据表中,所以我可以将它转换为html表,如下所示,tks
- 插件: 也许我没有清楚地解释清楚,列表是动态列表,分组列表可以有很多&#34; FieldName&#34; 我尝试做的是将列表与UserID分组,然后选择一个列表,其中包含最大数量&#34; FieldName&#34;,将它们转换为&#34; DataTable Columns&#34;然后将每个分组列表记录循环到DataTable.NewRow
类似这样的事情
乔伊威廉姆斯微软
然后我可以将它循环到html表