目前我使用一個列表來存儲我的數據的一個組成部分,它的正常使用格式爲:多維列表
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