我希望能够创建一个包含员工编号、姓和名的列表,并将其添加到下拉列表中,以显示姓、名。
目前为止,我已经为员工创建了一个类:
public class Employee
{
public int emp_Id;
public string lastName;
public string firstName;
public Employee(int id, string last, string first)
{
this.emp_Id = id;
this.lastName = last;
this.firstName = first;
}
}
并创建了一个列表来填充:
private List<Employee> employeeList = new List<Employee>();
这个列表是从SQL查询中获取的,然后按照姓氏进行排序。
foreach (DataRow row in ds.Tables["EMPLOYEE_TABLE"].Rows)
{
employeeList.Add(new Employee(int.Parse(row["EMP_ID"].ToString()),
row["LAST_NAME"].ToString(), row["FIRST_NAME"].ToString()));
}
employeeList.Sort(delegate(Employee E1, Employee E2) { return E1.lastName.CompareTo(E2.lastName); });
到目前为止,一切都按照我的意愿进行,但我无法弄清楚如何将下拉列表填充为包含在列表中的姓和名字值。
代码已编辑以提高可读性