目前我使用一个列表来存储我的数据的一个组成部分,它的正常使用格式为:多维列表
Item
----------------
Joe Bloggs
George Forman
Peter Pan
现在,我希望将其他行添加到这个列表,它的工作就像这样:
NAME EMAIL
------------------------------------------------------
Joe Bloggs [email protected]
George Forman [email protected]
Peter Pan [email protected]
我已经使用这个代码创建一个列表中的列表试过了,这段代码是另一种方法用在foreach循环:
// Where List is instantiated
List<List<string>> list2d = new List<List<string>>
...
// Where DataGrid instance is given the list
dg.DataSource = list2d;
dg.DataBind();
...
// In another method, where all people add their names and emails, then are added
// to the two-dimensional list
foreach (People p in ppl.results) {
list.Add(results.name);
list.Add(results.email);
list2d.Add(list);
}
当我运行它,我得到这样的结果:
Capacity Count
----------------
16 16
16 16
16 16
... ...
我要去哪里错在这里。我怎样才能得到我现在使用的代码所需的输出?
也许我是误解,但这看起来不像列表清单,而是一个记录列表,每个列表都有两个字段。如果是这样,也许这就是你应该如何建模。 – 2009-08-03 12:40:22