/// <summary> /// Adds the edit controls. /// </summary> /// <param name="category">The category.</param> /// <param name="attributeKeys">The attribute keys.</param> /// <param name="item">The item.</param> /// <param name="parentControl">The parent control.</param> /// <param name="validationGroup">The validation group.</param> /// <param name="setValue">if set to <c>true</c> [set value].</param> /// <param name="exclude">The exclude.</param> public static void AddEditControls( string category, List<string> attributeKeys, IHasAttributes item, Control parentControl, string validationGroup, bool setValue, List<string> exclude ) { HtmlGenericControl fieldSet; if ( parentControl is DynamicControlsPanel ) { fieldSet = new DynamicControlsHtmlGenericControl( "fieldset" ); } else { fieldSet = new HtmlGenericControl( "fieldset" ); } parentControl.Controls.Add( fieldSet ); fieldSet.Controls.Clear(); if ( !string.IsNullOrEmpty( category ) ) { HtmlGenericControl legend = new HtmlGenericControl( "h4" ); fieldSet.Controls.Add( legend ); legend.Controls.Clear(); legend.InnerText = category.Trim(); } foreach ( string key in attributeKeys ) { var attribute = item.Attributes[key]; if ( !exclude.Contains( attribute.Name ) ) { // Add the control for editing the attribute value attribute.AddControl( fieldSet.Controls, item.AttributeValues[attribute.Key].Value, validationGroup, setValue, true ); } } }
/// <summary> /// Adds the edit controls. /// </summary> /// <param name="category">The category.</param> /// <param name="attributeKeys">The attribute keys.</param> /// <param name="item">The item.</param> /// <param name="parentControl">The parent control.</param> /// <param name="validationGroup">The validation group.</param> /// <param name="setValue">if set to <c>true</c> [set value].</param> /// <param name="exclude">The exclude.</param> /// <param name="numberOfColumns">The number of columns.</param> public static void AddEditControls( string category, List<string> attributeKeys, IHasAttributes item, Control parentControl, string validationGroup, bool setValue, List<string> exclude, int? numberOfColumns ) { // ensure valid number of columns if ( numberOfColumns.HasValue && numberOfColumns.Value > 12) { numberOfColumns = 12; } HtmlGenericControl fieldSet; if ( parentControl is DynamicControlsPanel ) { fieldSet = new DynamicControlsHtmlGenericControl( "fieldset" ); } else { fieldSet = new HtmlGenericControl( "fieldset" ); } parentControl.Controls.Add( fieldSet ); fieldSet.Controls.Clear(); if ( !string.IsNullOrEmpty( category ) ) { HtmlGenericControl legend = new HtmlGenericControl( "h4" ); if ( numberOfColumns.HasValue ) { HtmlGenericControl row = new HtmlGenericControl( "div" ); row.AddCssClass( "row" ); fieldSet.Controls.Add( row ); HtmlGenericControl col = new HtmlGenericControl( "div" ); col.AddCssClass( "col-md-12" ); row.Controls.Add( col ); col.Controls.Add( legend ); } else { fieldSet.Controls.Add( legend ); } legend.Controls.Clear(); legend.InnerText = category.Trim(); } HtmlGenericControl attributeRow = new HtmlGenericControl( "div" ); if ( numberOfColumns.HasValue ) { fieldSet.Controls.Add( attributeRow ); attributeRow.AddCssClass( "row" ); } foreach ( string key in attributeKeys ) { var attribute = item.Attributes[key]; if ( !exclude.Contains( attribute.Name ) && !exclude.Contains( attribute.Key ) ) { // Add the control for editing the attribute value if ( numberOfColumns.HasValue ) { int colSize = (int)Math.Ceiling((double)12 / numberOfColumns.Value); HtmlGenericControl attributeCol = new HtmlGenericControl( "div" ); attributeRow.Controls.Add( attributeCol ); attributeCol.AddCssClass( string.Format( "col-md-{0}", colSize ) ); attribute.AddControl( attributeCol.Controls, item.AttributeValues[attribute.Key].Value, validationGroup, setValue, true ); } else { attribute.AddControl( fieldSet.Controls, item.AttributeValues[attribute.Key].Value, validationGroup, setValue, true ); } } } }