protected void Page_Init(object sender, EventArgs e) { using (WebhostEntities db = new WebhostEntities()) { int id = ((BasePage)Page).user.ID; Faculty faculty = db.Faculties.Where(fac => fac.ID == id).Single(); List <int> depts = faculty.Departments.Select(d => d.id).ToList(); DepartmentDDL.DataSource = DepartmentListItem.GetDataSource(depts); DepartmentDDL.DataTextField = "Text"; DepartmentDDL.DataValueField = "ID"; DepartmentDDL.DataBind(); } }
public void Initialize() { using (WebhostEntities db = new WebhostEntities()) { List <int> depts = new List <int>(); foreach (RequestableCourse rc in db.RequestableCourses.Where(r => r.TermId == TermId).ToList()) { if (!depts.Contains(rc.Course.DepartmentID)) { depts.Add(rc.Course.DepartmentID); } } DeptDDL.DataSource = DepartmentListItem.GetDataSource(depts); DeptDDL.DataTextField = "Text"; DeptDDL.DataValueField = "ID"; DeptDDL.DataBind(); //DeptDDL.SelectedIndex = 0; } }