在下面的源代码中,我从users
集合中选择了一个属性子集,我需要将它绑定到一个下拉列表:
var locationDepts = (from u in users select new { u.RcNumber, u.RcName }).Distinct().ToList();
if(!locationDepts.Count.Equals(0))
{
ddlRCListPerBuilding.DataSource = locationDepts;
ddlRCListPerBuilding.DataValueField = "RcNumber";
//Want to format display test "RCNumber - RcName"
ddlRCListPerBuilding.DataTextField = string.Format("{0} - {1}", locationDepts.RcNumber, locationDepts.RcName);
ddlRCListPerBuilding.DataBind();
}
我想将列表项显示文本格式化为匿名类型 RcNumber 和 RcName 的组合。如何访问匿名类型的属性以指示下拉列表项的文本格式?