/// <summary> /// Binds the defined values grid. /// </summary> protected void BindDefinedValuesGrid() { if ( _definedType != null ) { var queryable = new DefinedValueService( new RockContext() ).Queryable().Where( a => a.DefinedTypeId == _definedType.Id ).OrderBy( a => a.Order ); var result = queryable.ToList(); gDefinedValues.DataSource = result; gDefinedValues.DataBind(); } }
/// <summary> /// Binds the defined values grid. /// </summary> protected void BindDefinedValuesGrid() { AttributeService attributeService = new AttributeService(); int definedTypeId = hfDefinedTypeId.ValueAsInt(); // add attributes with IsGridColumn to grid string qualifierValue = hfDefinedTypeId.Value; var qryDefinedTypeAttributes = attributeService.GetByEntityTypeId( new DefinedValue().TypeId ).AsQueryable() .Where( a => a.EntityTypeQualifierColumn.Equals( "DefinedTypeId", StringComparison.OrdinalIgnoreCase ) && a.EntityTypeQualifierValue.Equals( qualifierValue ) ); qryDefinedTypeAttributes = qryDefinedTypeAttributes.Where( a => a.IsGridColumn ); List<Attribute> gridItems = qryDefinedTypeAttributes.ToList(); foreach ( var item in gDefinedValues.Columns.OfType<AttributeField>().ToList() ) { gDefinedValues.Columns.Remove( item ); } foreach ( var item in gridItems.OrderBy( a => a.Order ).ThenBy( a => a.Name ) ) { string dataFieldExpression = item.Key; bool columnExists = gDefinedValues.Columns.OfType<AttributeField>().FirstOrDefault( a => a.DataField.Equals( dataFieldExpression ) ) != null; if ( !columnExists ) { AttributeField boundField = new AttributeField(); boundField.DataField = dataFieldExpression; boundField.HeaderText = item.Name; boundField.SortExpression = string.Empty; int insertPos = gDefinedValues.Columns.IndexOf( gDefinedValues.Columns.OfType<DeleteField>().First()); gDefinedValues.Columns.Insert(insertPos, boundField ); } } var queryable = new DefinedValueService().Queryable().Where( a => a.DefinedTypeId == definedTypeId ).OrderBy( a => a.Order ); var result = queryable.ToList(); gDefinedValues.DataSource = result; gDefinedValues.DataBind(); }
/// <summary> /// Binds the grid for defined values. /// </summary> /// <param name="typeId">The type id.</param> protected void rGridValue_Bind( string typeId ) { int definedTypeId = Int32.Parse( typeId ); var queryable = new DefinedValueService().Queryable(). Where( a => a.DefinedTypeId == definedTypeId ); SortProperty sortProperty = rGridValue.SortProperty; if ( sortProperty != null ) queryable = queryable. Sort( sortProperty ); else queryable = queryable. OrderBy( a => a.Id); rGridValue.DataSource = queryable.ToList(); rGridValue.DataBind(); }