public static void Populate(this DropDownList ddl, DropDownType type, string defaultSelectionValue = null, bool retainFirst = false) { switch (type) { case DropDownType.Role: using (RolesController rc = new RolesController()) { var roles = rc.Get().Select(i => new { Label = i.RoleName, Value = i.RoleID }).OrderBy(i => i.Label).ToList(); ddl.DataSource = roles; } break; case DropDownType.ScopeType: using (ScopesController sc = new ScopesController()) { var scopes = sc.Get().Select(i => new { Label = i.ScopeName, Value = i.ScopeID }).OrderBy(i => i.Label).ToList(); ddl.DataSource = scopes; } break; case DropDownType.Permission: using (PermissionsController pc = new PermissionsController()) { var permissions = pc.Get().Select(i => new { Label = i.PermissionName, Value = i.PermissionID }).OrderBy(i => i.Label).ToList(); ddl.DataSource = permissions; } break; default: break; } Reset(ddl, retainFirst); ddl.DataValueField = "Value"; ddl.DataTextField = "Label"; ddl.DataBind(); SelectDefault(ddl, defaultSelectionValue); }