📅  最后修改于: 2022-03-11 14:57:34.710000             🧑  作者: Mango
using (MyTestDBEntities context = new MyTestDBEntities())
{
var query = context.UserTables.Where(p => p.City != null)
.Select(cc => new { DisplayValue = cc.UserID, DisplayText = cc.FirstName + " " + cc.LastName + " " + cc.City });
DropDownList1.DataSource = query.ToList();
DropDownList1.DataTextField = "DisplayText";
DropDownList1.DataValueField = "DisplayValue";
DropDownList1.DataBind();
}