public static List <DbEntities.Subjects.SubjectCategory> LoadSubjectCategory(ref DropDownList cmbCategory, int schoolId, bool includeTopAlso = false, bool includeEmptyField = false, int selectedValue = 0) { cmbCategory.DataTextField = "Name"; cmbCategory.DataValueField = "Id"; using (var helper = new DbHelper.Subject()) { var cats = helper.GetCategories(schoolId); if (includeTopAlso) { cats.Insert(0, new DbEntities.Subjects.SubjectCategory() { Id = 0, Name = " Top " }); } if (includeEmptyField) { cats.Insert(0, new DbEntities.Subjects.SubjectCategory() { Id = -1, Name = "" }); } cmbCategory.DataSource = cats; cmbCategory.DataBind(); if (selectedValue > 0) { var index = cats.IndexOf(cats.First(x => x.Id == selectedValue)); if (index >= 0) { cmbCategory.SelectedIndex = index; } } return(cats.ToList()); } }