protected void BindDropdown(UaFootball_DBDataContext db, Constants.ObjectType objectType, DropDownList ddl, bool addEmptyValue, string filter) { IEnumerable <GenericReferenceObject> dataSource = GetGenericReferenceData(db, objectType); if (filter.Length > 0) { dataSource = dataSource.Where(d => d.GenericStringValue.Equals(filter)); } ddl.DataSource = dataSource; ddl.DataTextField = "Name"; ddl.DataValueField = "Value"; ddl.DataBind(); if (addEmptyValue) { ddl.Items.Insert(0, new ListItem { Text = Constants.UI.DropdownDefaultText, Value = Constants.UI.DropdownDefaultValue }); } }
protected IEnumerable <GenericReferenceObject> GetGenericReferenceData(UaFootball_DBDataContext db, Constants.ObjectType objectType) { IEnumerable <GenericReferenceObject> data = new List <GenericReferenceObject>().AsEnumerable(); switch (objectType) { case Constants.ObjectType.FIFAAssociation: { data = db.FIFAAssociations.Select(f => new GenericReferenceObject { Name = f.FIFAAssociation_Name, Value = f.FIFAAssociation_ID }); break; } case Constants.ObjectType.Country: { data = db.Countries.OrderBy(c => c.Country_Name).Select(c => new GenericReferenceObject { Name = c.Country_Name, Value = c.Country_ID }); break; } case Constants.ObjectType.City: { data = db.Cities.OrderBy(c => c.City_Name).Select(c => new GenericReferenceObject { Name = c.City_Name, Value = c.City_ID }); break; } case Constants.ObjectType.Competition: { data = db.Competitions.Select(c => new GenericReferenceObject { Name = c.Competition_Name, Value = c.Competition_Id, GenericStringValue = c.CompetitionLevel_Cd }); break; } case Constants.ObjectType.Season: { data = db.Seasons.OrderByDescending(s => s.StartDate).Select(s => new GenericReferenceObject { Name = s.Season_Description, Value = s.Season_Id, GenericStringValue = s.CompetitionLevel_Cd }); break; } case Constants.ObjectType.Stadium: { data = db.Stadiums.OrderBy(s => s.Stadium_Name).Select(s => new GenericReferenceObject { Name = string.Concat(s.Stadium_Name, " (", s.City.City_Name, ")"), Value = s.Stadium_Id }); break; } case Constants.ObjectType.CompetitionStage: { data = db.CompetitionStages.Select(c => new GenericReferenceObject { Name = c.CompetitionStage_Name, Value = c.CompetitionStage_ID, GenericStringValue = c.Competition_ID.ToString() }); break; } default: break; } return(data); }