2¡¢ListViewºÍºÍÏÂÀ­²Ëµ¥DropDownList½áºÏ£¨ÆäËû¿Ø¼þÆäʵҲ²î²»¶à£©£º ǰ¶Ë´úÂ룺 ¡¡¡¡¡¡¡¡¡¡¡¡ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡<%# Eval("name") %> ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡<%# Eval("age") %> ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ¡¡¡¡¡¡¡¡¡¡¡¡ ¡¡¡¡¡¡¡¡
Ä£ÄâÊý¾ÝÌṩ´úÂ룺 namespace Data { ¡¡¡¡/// ¡¡¡¡///DataAccess µÄժҪ˵Ã÷ ¡¡¡¡/// ¡¡¡¡public class DataAccess ¡¡¡¡{ ¡¡¡¡¡¡¡¡public List List; ¡¡¡¡¡¡¡¡public DataAccess() ¡¡¡¡¡¡¡¡{ ¡¡¡¡¡¡¡¡¡¡¡¡List = new List(); ¡¡¡¡¡¡¡¡¡¡¡¡Employee e1 = new Employee { ID = 1, Name = "A", Age = 10 ,Sex=1}; ¡¡¡¡¡¡¡¡¡¡¡¡Employee e2 = new Employee { ID = 3, Name = "M", Age = 30 ,Sex=0}; ¡¡¡¡¡¡¡¡¡¡¡¡Employee e3 = new Employee { ID = 2, Name = "B", Age = 40,Sex=1 }; ¡¡¡¡¡¡¡¡¡¡¡¡Employee e4 = new Employee { ID = 4, Name = "S", Age = 19,Sex=0 }; ¡¡¡¡¡¡¡¡¡¡¡¡Employee e5 = new Employee { ID = 6, Name = "X", Age = 18 ,Sex=1}; ¡¡¡¡¡¡¡¡¡¡¡¡Employee e6 = new Employee { ID = 5, Name = "W", Age = 20 ,Sex=0}; ¡¡¡¡¡¡¡¡¡¡¡¡List.Add(e1); ¡¡¡¡¡¡¡¡¡¡¡¡List.Add(e2); ¡¡¡¡¡¡¡¡¡¡¡¡List.Add(e3); ¡¡¡¡¡¡¡¡¡¡¡¡List.Add(e4); ¡¡¡¡¡¡¡¡¡¡¡¡List.Add(e5); ¡¡¡¡¡¡¡¡¡¡¡¡List.Add(e6); ¡¡¡¡¡¡¡¡} ¡¡¡¡¡¡¡¡public Employee Find( int id) ¡¡¡¡¡¡¡¡{ ¡¡¡¡¡¡¡¡¡¡¡¡foreach (var item in List) ¡¡¡¡¡¡¡¡¡¡¡¡{ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡if (item.ID == id) ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡return item; ¡¡¡¡¡¡¡¡¡¡¡¡} ¡¡¡¡¡¡¡¡¡¡¡¡return null; ¡¡¡¡¡¡¡¡} ¡¡¡¡} ¡¡¡¡public class Employee ¡¡¡¡{ ¡¡¡¡¡¡¡¡public int ID { get; set; } ¡¡¡¡¡¡¡¡public string Name { get; set; } ¡¡¡¡¡¡¡¡public int Age { get; set; } ¡¡¡¡¡¡¡¡public int Sex { get; set; } ¡¡¡¡} } ºǫ́´úÂ룺 protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e) ¡¡¡¡{ ¡¡¡¡¡¡¡¡DropDownList SexDropDownList = e.Item.FindControl("SexDropDownList") as DropDownList; ¡¡¡¡¡¡¡¡int sex = da.Find(Convert.ToInt32((e.Item.FindControl("ID") as Label).Text)).Sex; ¡¡¡¡¡¡¡¡ListItem listItem; ¡¡¡¡¡¡¡¡if (sex == 0) ¡¡¡¡¡¡¡¡{ ¡¡¡¡¡¡¡¡¡¡¡¡listItem = new ListItem("ÄÐ", sex.ToString()); ¡¡¡¡¡¡¡¡} ¡¡¡¡¡¡¡¡else ¡¡¡¡¡¡¡¡{ ¡¡¡¡¡¡¡¡¡¡¡¡listItem = new ListItem("Å®", sex.ToString()); ¡¡¡¡¡¡¡¡} ¡¡¡¡¡¡¡¡SexDropDownList.Items.Add(listItem); ¡¡¡¡¡¡¡¡SexDropDownList.Enabled = false; ¡¡¡¡}