我正在使用实体框架数据库,我想从表中填充我的下拉列表,但顺序正确。
现在我正在使用代码:
var databaseList = from p in db.TECHNICAL_SKILLS
where p.skill_type == "Database"
select new EmployeeTechnicalSkillInfo
{
TechnicalSkillId = p.technical_skill_id,
SkillType = p.skill_type,
SkillName = p.skill_name
};
List<object> sDataValue = new List<object>();
sDataValue.Add("- Select -");
sDataValue.Remove("Other");
foreach (var vData in databaseList)
{
sDataValue.Add(vData.SkillName);
}
sDataValue.Add("Other");
DropDownListDB.DataSource = sDataValue.ToArray();
DropDownListDB.DataBind();
这是解决方案
var databaseList = from p in db.TECHNICAL_SKILLS
where p.skill_type == "Database"
orderby p.skill_name != "Other" descending, p.skill_name
select new EmployeeTechnicalSkillInfo
{
TechnicalSkillId = p.technical_skill_id,
SkillType = p.skill_type,
SkillName = p.skill_name
};