目前我使用一个列表来存储我的数据的一部分,并且它以这种格式完美地工作:
Item
----------------
Joe Bloggs
George Forman
Peter Pan
Run Code Online (Sandbox Code Playgroud)
现在,我想在此列表中添加另一行,因为它可以这样工作:
NAME EMAIL
------------------------------------------------------
Joe Bloggs joe@bloggs.com
George Forman george@formangrills.co
Peter Pan me@neverland.com
Run Code Online (Sandbox Code Playgroud)
我已经尝试使用此代码在列表中创建列表,并且此代码在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);
}
Run Code Online (Sandbox Code Playgroud)
当我运行这个时,我得到了这个结果:
Capacity Count …Run Code Online (Sandbox Code Playgroud)