我有一个下拉列表如下:
DropDownList1.DataSource = Students.GetStudents();
DropDownList1.DataBind();
-----------
我有一个 DataAccess 类,如下所示:
public IEnumerable<StudentEntity> GetStudents()
{
List<StudentsEntity> studentsList = new List<StudentsEntity>();
studentsList = Service.GetList() // some service getting a list of sutdents
return new BindingList<StudentEntity>(studentsList);
}
我有一个 DataObject 类,如下所示:
public class StudentEntity : IComparable
{
public string fullname { get {return firstName +", "+ lastName;}
public string ID {get; set;}
public string Height {get; set;}
public string Firstname {get; set;}
public string Lastname {get; set;}
public int CompareTo(object obj)
{
StudentEntity entity = (StudentEntity) obj;
return Lastname.CompareTo(entity.Lastname);
}
}
在 UI 级别 - “学生全名”显示在下拉列表中,那么如何从下拉列表中获取所选学生的“ID”?