Пример #1
0
 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();
     }
 }
Пример #2
0
        /// <summary>
        /// Get a Datasource List for use in Web Controls.
        ///
        /// DataTextField = "Text"
        /// DataValueField = "Id"
        ///
        /// Invalid IDs are dropped without notification.
        ///
        /// </summary>
        /// <param name="actids">List of RequestableCourse.id</param>
        /// <returns></returns>
        public static List <DepartmentListItem> GetDataSource(List <int> actids)
        {
            List <DepartmentListItem> items = new List <DepartmentListItem>();

            foreach (int id in actids)
            {
                DepartmentListItem item = new DepartmentListItem(id);
                if (item.ID != -1)
                {
                    items.Add(item);
                }
            }

            return(items);
        }
Пример #3
0
        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;
            }
        }