我试图填充下拉列表,但它似乎没有填充,我不知道为什么它不是。你能再给我一双眼睛帮我找出我哪里做错了吗?下面是我的代码:
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();
}
}
尝试添加一个ToList();
ddlSemester.DataSource = semester.ToList();