protected void Page_Init(object sender, EventArgs e) { using (WebhostEntities db = new WebhostEntities()) { List <int> ids = db.Faculties.OrderBy(f => f.LastName).ThenBy(f => f.FirstName).Select(f => f.ID).ToList(); FacultySelector.DataSource = FacultyListItem.GetDataSource(ids); FacultySelector.DataTextField = "Text"; FacultySelector.DataValueField = "ID"; FacultySelector.DataBind(); } }
protected void LoadTable() { using (WebhostEntities db = new WebhostEntities()) { SelectedTable.Rows.Clear(); if (GroupIds.Count == 0) { RemoveBtn.Visible = false; RemoveList.Visible = false; return; } foreach (int id in GroupIds) { Faculty faculty = db.Faculties.Where(f => f.ID == id).Single(); TableRow row = new TableRow(); TableCell cell = new TableCell(); Label lbl = new Label() { Text = String.Format("{0} {1}", faculty.FirstName, faculty.LastName) }; cell.Controls.Add(lbl); row.Cells.Add(cell); SelectedTable.Rows.Add(row); } RemoveList.Visible = true; RemoveBtn.Visible = true; /* RemoveList.DataSource = (from faculty in db.Faculties.Where(f => GroupIds.Contains(f.ID)) * orderby faculty.LastName, faculty.FirstName * select new * { * Name = faculty.FirstName + " " + faculty.LastName, * ID = faculty.ID * }).ToList();*/ RemoveList.DataSource = FacultyListItem.GetDataSource(GroupIds); RemoveList.DataTextField = "Text"; RemoveList.DataValueField = "ID"; RemoveList.DataBind(); } }