0

我正在尝试填充 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();                
        }
    }
4

1 回答 1

1

尝试添加一个 ToList();

ddlSemester.DataSource = semester.ToList();
于 2013-01-17T20:29:48.240 回答