我正在尝试填充DropDownlist,但它似乎没有填充,我不知道为什么它不是。我可以得到第二双眼睛来帮助我弄清楚我错在哪里吗? 以下是我的代码:
private testhousingEntities1 canceldb = new testhousingEntities1();
/*=================================================*/
/*load form */
/*=================================================*/
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
InitializeForm();
}
}
/*================================================*/
/* */
/*================================================*/
private void InitializeForm()
{
var version = (from v in canceldb.CancellationVersions
where v.Active
select v).FirstOrDefault();
/*populating states and countries drop downlist */
FormHelpers.GenerateStates(ddlState);
FormHelpers.GenerateCountries(ddlCountry);
/*populating drop downlist */
semesterList();
}
/*=================================================*/
/*populating the Semester drop downlist */
/*=================================================*/
private void semesterList()
{
ddlSemester.Items.Insert(0, new ListItem("---------", "000"));
var semester = from s in canceldb.cancellationsemesters
select new {
cid= s.id, cSemester = s.Semester,
};
ddlSemester.DataSource = semester;
ddlSemester.DataTextField = "cSemester";
ddlSemester.DataValueField = "cid";
ddlSemester.DataBind();
}
/*=================================================*/
/*populating the Semester drop downlist */
/*=================================================*/
protected void ddlSemester_SelectedIndexChanged(object sender, EventArgs e)
{
if (!IsPostBack)
{
semesterList();
}
}
答案 0 :(得分:1)
尝试添加ToList();
ddlSemester.DataSource = semester.ToList();