public class DataList1Page : Page { protected DataList peopleDataList;
protected string GetColorName(Color c) { return TypeDescriptor.GetConverter(typeof(Color)).Convert ToString(c); }
private void LoadPeopleList() { // 創(chuàng)建數(shù)據(jù)源 Person[] people = new Person[] { new Person("Nikhil Kothari", Color.Green), new Person("Steve Millet", Color.Purple), new Person("Chris Anderson", Color.Blue), new Person("Mike Pope", Color.Orange), new Person("Anthony Moore", Color.Yellow), new Person("Jon Jung", Color.MediumAquamarine), new Person("Susan Warren", Color.SlateBlue), new Person("Izzy Gryko", Color.Red) };
此示例中所用的數(shù)據(jù)源是 Person 對象的一個(gè)簡單數(shù)組。由于每個(gè)數(shù) 組都實(shí)現(xiàn)ICollection方法,所以數(shù)組適合用作數(shù)據(jù)源。這顯示了將數(shù)據(jù) 結(jié)構(gòu)和類型用作數(shù)據(jù)源時(shí)可獲得的靈活程度。
DataList1 示例介紹了下列概念:
●在模板中定義豐富的 HTML UI ●使用簡單數(shù)組作為數(shù)據(jù)源 ●通過程序設(shè)置數(shù)據(jù)源 ●數(shù)據(jù)綁定語法中所允許的各種表達(dá)式