protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { using (WebhostEntities db = new WebhostEntities()) { int year = DateRange.GetCurrentAcademicYear(); TemplateDDL.DataSource = WeekendListItem.GetDataSource(db.Weekends.Where(w => w.DutyTeam.AcademicYearID == year).OrderByDescending(w => w.StartDate).Select(w => w.id).ToList()); TemplateDDL.DataTextField = "Text"; TemplateDDL.DataValueField = "WeekendId"; TemplateDDL.DataBind(); } BuilderPanel.Visible = WeekendID != -1; } }
public static List <WeekendListItem> GetDataSource(List <int> ids) { List <WeekendListItem> weekends = new List <WeekendListItem>(); foreach (int id in ids) { WeekendListItem item = new WeekendListItem(id); if (item._wkid == -1) { continue; } weekends.Add(new WeekendListItem(id)); } return(weekends); }