/// <summary> /// Performs basic instance initialization for a data control field. /// </summary> /// <param name="sortingEnabled">A value that indicates whether the control supports the sorting of columns of data.</param> /// <param name="control">The data control that owns the <see cref="T:System.Web.UI.WebControls.DataControlField"/>.</param> /// <returns> /// Always returns false. /// </returns> public override bool Initialize( bool sortingEnabled, Control control ) { EditFieldTemplate editFieldTemplate = new EditFieldTemplate(); editFieldTemplate.LinkButtonClick += editFieldTemplate_LinkButtonClick; this.ItemTemplate = editFieldTemplate; ParentGrid = control as Grid; return base.Initialize( sortingEnabled, control ); }
/// <summary> /// Performs basic instance initialization for a data control field. /// </summary> /// <param name="sortingEnabled">A value that indicates whether the control supports the sorting of columns of data.</param> /// <param name="control">The data control that owns the <see cref="T:System.Web.UI.WebControls.DataControlField"/>.</param> /// <returns> /// Always returns false. /// </returns> public override bool Initialize( bool sortingEnabled, Control control ) { DeleteFieldTemplate deleteFieldTemplate = new DeleteFieldTemplate(); deleteFieldTemplate.LinkButtonClick += deleteFieldTemplate_LinkButtonClick; this.ItemTemplate = deleteFieldTemplate; this.ParentGrid = control as Grid; return base.Initialize( sortingEnabled, control ); }
/// <summary> /// Gets the sorted view. /// </summary> /// <param name="dataTable">The data table.</param> /// <returns></returns> private void SortTable( Grid grid, DataTable dataTable ) { System.Data.DataView dataView = dataTable.DefaultView; SortProperty sortProperty = grid.SortProperty; if ( sortProperty != null ) { dataView.Sort = string.Format( "{0} {1}", sortProperty.Property, sortProperty.DirectionString ); } }
/// <summary> /// Gets the sorted view. /// </summary> /// <param name="dataTable">The data table.</param> /// <returns></returns> private void FilterTable( Grid grid, DataTable dataTable ) { var showGridFilterControls = GetAttributeValue( "ShowGridFilter" ).AsBoolean(); System.Data.DataView dataView = dataTable.DefaultView; if ( !showGridFilterControls ) { dataView.RowFilter = null; return; } var query = new List<string>(); foreach ( var control in GridFilter.Controls.OfType<Control>() ) { if ( control is DateRangePicker ) { var dateRangePicker = control as DateRangePicker; var minValue = dateRangePicker.LowerValue; var maxValue = dateRangePicker.UpperValue; var colName = GridFilterColumnLookup[control]; if ( minValue.HasValue ) { query.Add( string.Format( "[{0}] >= #{1}#", colName, minValue.Value ) ); } if ( maxValue.HasValue ) { query.Add( string.Format( "[{0}] < #{1}#", colName, maxValue.Value.AddDays( 1 ) ) ); } } else if ( control is RockDropDownList ) { var dropDownList = control as RockDropDownList; var doFilter = !string.IsNullOrWhiteSpace( dropDownList.SelectedValue ); if ( doFilter ) { var value = dropDownList.SelectedValue == true.ToYesNo() ? "1" : "0"; var colName = GridFilterColumnLookup[control]; query.Add( string.Format( "[{0}] = {1}", colName, value ) ); } } else if ( control is RockTextBox ) { var textBox = control as RockTextBox; var value = textBox.Text; var colName = GridFilterColumnLookup[control]; var colIndex = dataView.Table.Columns.IndexOf( colName ); if ( colIndex != -1 && !string.IsNullOrWhiteSpace( value ) ) { var col = dataView.Table.Columns[colIndex]; if ( col.DataType.Name == "String" ) { query.Add( string.Format( "[{0}] LIKE '%{1}%'", colName, value ) ); } else if ( col.DataType.Name.StartsWith( "Int" ) ) { query.Add( string.Format( "[{0}] = {1}", colName, value ) ); } } } } dataView.RowFilter = string.Join( " AND ", query ); }
/// <summary> /// Adds the grid columns. /// </summary> /// <param name="dataTable">The data table.</param> private void AddGridColumns( Grid grid, DataTable dataTable ) { bool showColumns = GetAttributeValue( "ShowColumns" ).AsBoolean(); var columnList = GetAttributeValue( "Columns" ).SplitDelimitedValues().ToList(); int rowsToEval = 10; if ( dataTable.Rows.Count < 10 ) { rowsToEval = dataTable.Rows.Count; } grid.Columns.Clear(); if ( !string.IsNullOrWhiteSpace( grid.PersonIdField ) ) { grid.Columns.Add( new SelectField() ); } GridFilterColumnLookup = new Dictionary<Control, string>(); foreach ( DataColumn dataTableColumn in dataTable.Columns ) { if ( columnList.Count > 0 && ( ( showColumns && !columnList.Contains( dataTableColumn.ColumnName, StringComparer.OrdinalIgnoreCase ) ) || ( !showColumns && columnList.Contains( dataTableColumn.ColumnName, StringComparer.OrdinalIgnoreCase ) ) ) ) { continue; } BoundField bf = new BoundField(); var splitCaseName = dataTableColumn.ColumnName.SplitCase(); if ( dataTableColumn.DataType == typeof( bool ) ) { bf = new BoolField(); if ( GridFilter != null ) { var id = "ddl" + dataTableColumn.ColumnName.RemoveSpecialCharacters(); var filterControl = new RockDropDownList() { Label = splitCaseName, ID = id }; GridFilterColumnLookup.Add( filterControl, dataTableColumn.ColumnName ); filterControl.Items.Add( BoolToString( null ) ); filterControl.Items.Add( BoolToString( true ) ); filterControl.Items.Add( BoolToString( false ) ); GridFilter.Controls.Add( filterControl ); var value = GridFilter.GetUserPreference( id ); if ( value != null ) { filterControl.SetValue( value ); } } } else if ( dataTableColumn.DataType == typeof( DateTime ) ) { bf = new DateField(); for ( int i = 0; i < rowsToEval; i++ ) { object dateObj = dataTable.Rows[i][dataTableColumn]; if ( dateObj is DateTime ) { DateTime dateTime = ( DateTime ) dateObj; if ( dateTime.TimeOfDay.Seconds != 0 ) { bf = new DateTimeField(); break; } } } if ( GridFilter != null ) { var id = "drp" + dataTableColumn.ColumnName.RemoveSpecialCharacters(); var filterControl = new DateRangePicker() { Label = splitCaseName, ID = id, }; GridFilterColumnLookup.Add( filterControl, dataTableColumn.ColumnName ); GridFilter.Controls.Add( filterControl ); var value = GridFilter.GetUserPreference( id ); if ( value != null ) { DateTime upper; DateTime lower; if ( DateRangePicker.TryParse( value, out lower, out upper ) ) { filterControl.LowerValue = lower; filterControl.UpperValue = upper; } } } } else { bf.HtmlEncode = false; if ( GridFilter != null ) { var id = "tb" + dataTableColumn.ColumnName.RemoveSpecialCharacters(); var filterControl = new RockTextBox() { Label = splitCaseName, ID = id }; GridFilterColumnLookup.Add( filterControl, dataTableColumn.ColumnName ); GridFilter.Controls.Add( filterControl ); var key = filterControl.ID; var value = GridFilter.GetUserPreference( key ); if ( value != null ) { filterControl.Text = value; } } } bf.DataField = dataTableColumn.ColumnName; bf.SortExpression = dataTableColumn.ColumnName; bf.HeaderText = splitCaseName; grid.Columns.Add( bf ); } }
/// <summary> /// Binds the grid. /// </summary> /// <param name="grid">The grid.</param> /// <param name="dataView">The data view.</param> /// <returns></returns> private bool BindGrid( Grid grid, DataView dataView, int? fetchRowCount = null ) { var errorMessages = new List<string>(); grid.DataSource = null; if ( dataView.EntityTypeId.HasValue ) { var cachedEntityType = EntityTypeCache.Read( dataView.EntityTypeId.Value ); if ( cachedEntityType != null && cachedEntityType.AssemblyName != null ) { Type entityType = cachedEntityType.GetEntityType(); if ( entityType != null ) { grid.CreatePreviewColumns( entityType ); var qry = dataView.GetQuery( grid.SortProperty, out errorMessages ); if ( fetchRowCount.HasValue ) { qry = qry.Take( fetchRowCount.Value ); } grid.DataSource = qry.AsNoTracking().ToList(); } } } if ( grid.DataSource != null ) { grid.ExportFilename = dataView.Name; if ( errorMessages.Any() ) { nbEditModeMessage.Text = "INFO: There was a problem with one or more of the filters for this data view...<br/><br/> " + errorMessages.AsDelimited( "<br/>" ); } if ( dataView.EntityTypeId.HasValue ) { grid.RowItemText = EntityTypeCache.Read( dataView.EntityTypeId.Value ).FriendlyName; } grid.DataBind(); return true; } return false; }
/// <summary> /// Binds the grid. /// </summary> /// <param name="grid">The grid.</param> /// <param name="dataView">The data view.</param> /// <returns></returns> private bool BindGrid( Grid grid, DataView dataView, int? fetchRowCount = null ) { grid.DataSource = null; // Only respect the ShowResults option if fetchRowCount is null if ( !this.ShowResults && fetchRowCount == null ) { return false; } var errorMessages = new List<string>(); if ( dataView.EntityTypeId.HasValue ) { var cachedEntityType = EntityTypeCache.Read( dataView.EntityTypeId.Value ); if ( cachedEntityType != null && cachedEntityType.AssemblyName != null ) { Type entityType = cachedEntityType.GetEntityType(); if ( entityType != null ) { try { grid.CreatePreviewColumns( entityType ); var qry = dataView.GetQuery( grid.SortProperty, GetAttributeValue( "DatabaseTimeout" ).AsIntegerOrNull() ?? 180, out errorMessages ); if ( fetchRowCount.HasValue ) { qry = qry.Take( fetchRowCount.Value ); } grid.SetLinqDataSource( qry.AsNoTracking() ); grid.DataBind(); } catch ( Exception ex ) { this.LogException( ex ); Exception exception = ex; while ( exception != null ) { if ( exception is System.Data.SqlClient.SqlException ) { // if there was a SQL Server Timeout, have the warning be a friendly message about that. if ( ( exception as System.Data.SqlClient.SqlException ).Number == -2 ) { nbEditModeMessage.NotificationBoxType = NotificationBoxType.Warning; nbEditModeMessage.Text = "This dataview did not complete in a timely manner. You can try again or adjust the timeout setting of this block."; return false; } else { errorMessages.Add( exception.Message ); exception = exception.InnerException; } } else { errorMessages.Add( exception.Message ); exception = exception.InnerException; } } } } } } var errorBox = ( grid == gPreview) ? nbPreviewError : nbGridError; if ( errorMessages.Any() ) { errorBox.NotificationBoxType = NotificationBoxType.Warning; errorBox.Text = "WARNING: There was a problem with one or more of the filters for this data view...<br/><br/> " + errorMessages.AsDelimited( "<br/>" ); errorBox.Visible = true; } else { errorBox.Visible = false; } if ( dataView.EntityTypeId.HasValue ) { grid.RowItemText = EntityTypeCache.Read( dataView.EntityTypeId.Value ).FriendlyName; } if ( grid.DataSource != null ) { grid.ExportFilename = dataView.Name; return true; } return false; }
/// <summary> /// When implemented by a class, defines the <see cref="T:System.Web.UI.Control"/> object that child controls and templates belong to. These child controls are in turn defined within an inline template. /// </summary> /// <param name="container">The <see cref="T:System.Web.UI.Control"/> object to contain the instances of controls from the inline template.</param> public void InstantiateIn( Control container ) { DataControlFieldCell cell = container as DataControlFieldCell; if ( cell != null ) { GroupPickerField groupPickerField = cell.ContainingField as GroupPickerField; ParentGrid = groupPickerField.ParentGrid; ColumnIndex = groupPickerField.ColumnIndex; GroupPicker gp = new GroupPicker(); gp.ID = "groupPicker_" + ColumnIndex.ToString(); gp.RootGroupId = groupPickerField.RootGroupId; gp.SelectItem += gp_SelectItem; cell.Controls.Add( gp ); } }
/// <summary> /// Performs basic instance initialization for a data control field. /// </summary> /// <param name="sortingEnabled">A value that indicates whether the control supports the sorting of columns of data.</param> /// <param name="control">The data control that owns the <see cref="T:System.Web.UI.WebControls.DataControlField" />.</param> /// <returns> /// Always returns false. /// </returns> public override bool Initialize( bool sortingEnabled, Control control ) { LiquidFieldTemplate liquidFieldTemplate = new LiquidFieldTemplate(); this.ItemTemplate = liquidFieldTemplate; this.ParentGrid = control as Grid; return base.Initialize( sortingEnabled, control ); }
/// <summary> /// Creates the locations grid. /// </summary> private void CreateLocationsGrid() { _gLocations = new Grid(); _gLocations.ID = this.ID + "_gCheckinLabels"; _gLocations.DisplayType = GridDisplayType.Light; _gLocations.ShowActionRow = true; _gLocations.RowItemText = "Location"; _gLocations.Actions.ShowAdd = true; //// Handle AddClick manually in OnLoad() _gLocations.Actions.AddClick += AddLocation_Click; _gLocations.DataKeyNames = new string[] { "LocationId" }; _gLocations.TooltipField = "Name"; _gLocations.Columns.Add( new BoundField { DataField = "FullNamePath", HeaderText = "Name" } ); DeleteField deleteField = new DeleteField(); //// handle manually in OnLoad() deleteField.Click += DeleteLocation_Click; _gLocations.Columns.Add( deleteField ); Controls.Add( _gLocations ); }
/// <summary> /// Builds the controls. /// </summary> /// <param name="setData">if set to <c>true</c> [set data].</param> private void BuildControls( bool setData ) { string errorMessage = string.Empty; var dataSet = GetData( out errorMessage ); if ( !string.IsNullOrWhiteSpace( errorMessage ) ) { phContent.Visible = false; nbError.Text = errorMessage; nbError.Visible = true; } else { phContent.Controls.Clear(); if ( dataSet != null ) { string formattedOutput = GetAttributeValue( "FormattedOutput" ); if ( string.IsNullOrWhiteSpace( formattedOutput ) ) { bool personReport = GetAttributeValue( "PersonReport" ).AsBoolean(); int tableId = 0; foreach ( DataTable dataTable in dataSet.Tables ) { var div = new HtmlGenericControl( "div" ); div.AddCssClass( "grid" ); phContent.Controls.Add( div ); var grid = new Grid(); div.Controls.Add( grid ); grid.ID = string.Format( "dynamic_data_{0}", tableId++ ); grid.AllowSorting = true; grid.EmptyDataText = "No Results"; grid.GridRebind += gReport_GridRebind; grid.RowSelected += gReport_RowSelected; if ( personReport ) { grid.PersonIdField = "Id"; } else { grid.PersonIdField = null; } grid.CommunicateMergeFields = GetAttributeValue( "MergeFields" ).SplitDelimitedValues().ToList<string>(); AddGridColumns( grid, dataTable ); SetDataKeyNames( grid, dataTable ); if ( setData ) { SortTable( grid, dataTable ); grid.DataSource = dataTable; grid.DataBind(); } } } else { var mergeFields = Rock.Web.Cache.GlobalAttributesCache.GetMergeFields( CurrentPerson ); if ( CurrentPerson != null ) { // TODO: When support for "Person" is not supported anymore (should use "CurrentPerson" instead), remove this line mergeFields.Add( "Person", CurrentPerson ); mergeFields.Add( "CurrentPerson", CurrentPerson ); } mergeFields.Add( "RockVersion", Rock.VersionInfo.VersionInfo.GetRockProductVersionNumber() ); mergeFields.Add( "Campuses", CampusCache.All() ); int i = 1; foreach ( DataTable dataTable in dataSet.Tables ) { var dropRows = new List<DataRowDrop>(); foreach ( DataRow row in dataTable.Rows ) { dropRows.Add( new DataRowDrop( row ) ); } if ( dataSet.Tables.Count > 1 ) { var tableField = new Dictionary<string, object>(); tableField.Add( "rows", dropRows ); mergeFields.Add( "table" + i.ToString(), tableField ); } else { mergeFields.Add( "rows", dropRows ); } i++; } phContent.Controls.Add( new LiteralControl( formattedOutput.ResolveMergeFields( mergeFields ) ) ); } } phContent.Visible = true; nbError.Visible = false; } }
/// <summary> /// Adds the grid columns. /// </summary> /// <param name="dataTable">The data table.</param> private void AddGridColumns( Grid grid, DataTable dataTable ) { bool showColumns = bool.Parse( GetAttributeValue( "ShowColumns" ) ); var columnList = GetAttributeValue( "Columns" ).SplitDelimitedValues().ToList(); int rowsToEval = 10; if ( dataTable.Rows.Count < 10 ) { rowsToEval = dataTable.Rows.Count; } grid.Columns.Clear(); if ( !string.IsNullOrWhiteSpace( grid.PersonIdField ) ) { grid.Columns.Add( new SelectField() ); } foreach ( DataColumn dataTableColumn in dataTable.Columns ) { if ( columnList.Count > 0 && ( ( showColumns && !columnList.Contains( dataTableColumn.ColumnName, StringComparer.OrdinalIgnoreCase ) ) || ( !showColumns && columnList.Contains( dataTableColumn.ColumnName, StringComparer.OrdinalIgnoreCase ) ) ) ) { continue; } BoundField bf = new BoundField(); if ( dataTableColumn.DataType == typeof( bool ) ) { bf = new BoolField(); } else if ( dataTableColumn.DataType == typeof( DateTime ) ) { bf = new DateField(); for ( int i = 0; i < rowsToEval; i++ ) { object dateObj = dataTable.Rows[i][dataTableColumn]; if ( dateObj is DateTime ) { DateTime dateTime = (DateTime)dateObj; if ( dateTime.TimeOfDay.Seconds != 0 ) { bf = new DateTimeField(); break; } } } } else { bf.HtmlEncode = false; } bf.DataField = dataTableColumn.ColumnName; bf.SortExpression = dataTableColumn.ColumnName; bf.HeaderText = dataTableColumn.ColumnName.SplitCase(); grid.Columns.Add( bf ); } }
/// <summary> /// When implemented by a class, defines the <see cref="T:System.Web.UI.Control"/> object that child controls and templates belong to. These child controls are in turn defined within an inline template. /// </summary> /// <param name="container">The <see cref="T:System.Web.UI.Control"/> object to contain the instances of controls from the inline template.</param> public void InstantiateIn( Control container ) { DataControlFieldCell cell = container as DataControlFieldCell; if ( cell != null ) { DeleteField deleteField = cell.ContainingField as DeleteField; ParentGrid = deleteField.ParentGrid; LinkButton lbDelete = new LinkButton(); lbDelete.CausesValidation = false; lbDelete.CssClass = deleteField.ButtonCssClass; lbDelete.PreRender += ( s, e ) => { if ( lbDelete.Enabled && ( !ParentGrid.Enabled || !ParentGrid.IsDeleteEnabled ) ) { lbDelete.AddCssClass( "disabled" ); lbDelete.Enabled = false; } }; lbDelete.ToolTip = deleteField.Tooltip; HtmlGenericControl buttonIcon = new HtmlGenericControl( "i" ); buttonIcon.Attributes.Add( "class", deleteField.IconCssClass ); lbDelete.Controls.Add( buttonIcon ); lbDelete.Click += lbDelete_Click; lbDelete.DataBinding += lbDelete_DataBinding; // make sure delete button is registered for async postback (needed just in case the grid was created at runtime) var sm = ScriptManager.GetCurrent( this.ParentGrid.Page ); sm.RegisterAsyncPostBackControl( lbDelete ); cell.Controls.Add( lbDelete ); } }
/// <summary> /// Creates the checkin labels grid. /// </summary> private void CreateCheckinLabelsGrid() { _gCheckinLabels = new Grid(); // make the ID static so we can handle Postbacks from the Add and Delete actions _gCheckinLabels.ClientIDMode = System.Web.UI.ClientIDMode.Static; _gCheckinLabels.ID = this.ClientID + "_gCheckinLabels"; _gCheckinLabels.CssClass = "margin-b-md"; _gCheckinLabels.DisplayType = GridDisplayType.Light; _gCheckinLabels.ShowActionRow = true; _gCheckinLabels.RowItemText = "Label"; _gCheckinLabels.Actions.ShowAdd = true; //// Handle AddClick manually in OnLoad() //// gCheckinLabels.Actions.AddClick += AddCheckinLabel_Click; _gCheckinLabels.DataKeyNames = new string[] { "AttributeKey" }; _gCheckinLabels.Columns.Add( new BoundField { DataField = "BinaryFileId", Visible = false } ); _gCheckinLabels.Columns.Add( new BoundField { DataField = "FileName", HeaderText = "Name" } ); DeleteField deleteField = new DeleteField(); //// handle manually in OnLoad() //// deleteField.Click += DeleteCheckinLabel_Click; _gCheckinLabels.Columns.Add( deleteField ); Controls.Add( _gCheckinLabels ); }
/// <summary> /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering. /// </summary> protected override void CreateChildControls() { Controls.Clear(); _hfExpanded = new HiddenFieldWithClass(); Controls.Add(_hfExpanded); _hfExpanded.ID = this.ID + "_hfExpanded"; _hfExpanded.CssClass = "filter-expanded"; _hfExpanded.Value = "False"; _hfActivityTypeGuid = new HiddenField(); Controls.Add(_hfActivityTypeGuid); _hfActivityTypeGuid.ID = this.ID + "_hfActivityTypeGuid"; _lblActivityTypeName = new Label(); Controls.Add(_lblActivityTypeName); _lblActivityTypeName.ClientIDMode = ClientIDMode.Static; _lblActivityTypeName.ID = this.ID + "_lblActivityTypeName"; _lblActivityTypeDescription = new Label(); Controls.Add(_lblActivityTypeDescription); _lblActivityTypeDescription.ClientIDMode = ClientIDMode.Static; _lblActivityTypeDescription.ID = this.ID + "_lblActivityTypeDescription"; _lblInactive = new Label(); Controls.Add(_lblInactive); _lblInactive.ClientIDMode = ClientIDMode.Static; _lblInactive.ID = this.ID + "_lblInactive"; _lblInactive.CssClass = "pull-right"; _lblInactive.Text = "<span class='label label-danger'>Inactive</span>"; _lbDeleteActivityType = new LinkButton(); Controls.Add(_lbDeleteActivityType); _lbDeleteActivityType.CausesValidation = false; _lbDeleteActivityType.ID = this.ID + "_lbDeleteActivityType"; _lbDeleteActivityType.CssClass = "btn btn-xs btn-square btn-danger js-activity-delete"; _lbDeleteActivityType.Click += lbDeleteActivityType_Click; _lbDeleteActivityType.Controls.Add(new LiteralControl { Text = "<i class='fa fa-times'></i>" }); _sbSecurity = new SecurityButton(); Controls.Add(_sbSecurity); _sbSecurity.ID = this.ID + "_sbSecurity"; _sbSecurity.Attributes["class"] = "btn btn-security btn-xs security pull-right"; _sbSecurity.EntityTypeId = EntityTypeCache.Get(typeof(Rock.Model.WorkflowActivityType)).Id; _cbActivityTypeIsActive = new RockCheckBox { Text = "Active" }; Controls.Add(_cbActivityTypeIsActive); _cbActivityTypeIsActive.ID = this.ID + "_cbActivityTypeIsActive"; string checkboxScriptFormat = @" javascript: if ($(this).is(':checked')) {{ $('#{0}').hide(); $('#{1}').removeClass('workflow-activity-inactive'); }} else {{ $('#{0}').show(); $('#{1}').addClass('workflow-activity-inactive'); }} "; _cbActivityTypeIsActive.InputAttributes.Add("onclick", string.Format(checkboxScriptFormat, _lblInactive.ID, this.ID + "_section")); _tbActivityTypeName = new RockTextBox(); Controls.Add(_tbActivityTypeName); _tbActivityTypeName.ID = this.ID + "_tbActivityTypeName"; _tbActivityTypeName.Label = "Name"; _tbActivityTypeName.Required = true; _tbActivityTypeName.Attributes["onblur"] = string.Format("javascript: $('#{0}').text($(this).val());", _lblActivityTypeName.ID); _tbActivityTypeDescription = new RockTextBox(); Controls.Add(_tbActivityTypeDescription); _tbActivityTypeDescription.ID = this.ID + "_tbActivityTypeDescription"; _tbActivityTypeDescription.Label = "Description"; _tbActivityTypeDescription.TextMode = TextBoxMode.MultiLine; _tbActivityTypeDescription.Rows = 2; _tbActivityTypeDescription.Attributes["onblur"] = string.Format("javascript: $('#{0}').text($(this).val());", _lblActivityTypeDescription.ID); _cbActivityTypeIsActivatedWithWorkflow = new RockCheckBox { Text = "Activated with Workflow" }; Controls.Add(_cbActivityTypeIsActivatedWithWorkflow); _cbActivityTypeIsActivatedWithWorkflow.ID = this.ID + "_cbActivityTypeIsActivatedWithWorkflow"; checkboxScriptFormat = @" javascript: if ($(this).is(':checked')) {{ $('#{0}').addClass('activated-with-workflow'); }} else {{ $('#{0}').removeClass('activated-with-workflow'); }} "; _cbActivityTypeIsActivatedWithWorkflow.InputAttributes.Add("onclick", string.Format(checkboxScriptFormat, this.ID + "_section")); _lbAddActionType = new LinkButton(); Controls.Add(_lbAddActionType); _lbAddActionType.ID = this.ID + "_lbAddAction"; _lbAddActionType.CssClass = "btn btn-xs btn-action add-action"; _lbAddActionType.Click += lbAddActionType_Click; _lbAddActionType.CausesValidation = false; _lbAddActionType.Controls.Add(new LiteralControl { Text = "<i class='fa fa-plus'></i> Add Action" }); _pwAttributes = new PanelWidget(); Controls.Add(_pwAttributes); _pwAttributes.ID = this.ID + "_pwAttributes"; _pwAttributes.Title = "Activity Attributes"; _pwAttributes.CssClass = "attribute-panel"; _gAttributes = new Grid(); _pwAttributes.Controls.Add(_gAttributes); _gAttributes.ID = this.ID + "_gAttributes"; _gAttributes.AllowPaging = false; _gAttributes.DisplayType = GridDisplayType.Light; _gAttributes.RowItemText = "Activity Attribute"; _gAttributes.AddCssClass("attribute-grid"); _gAttributes.DataKeyNames = new string[] { "Guid" }; _gAttributes.Actions.ShowAdd = true; _gAttributes.Actions.AddClick += gAttributes_Add; _gAttributes.GridRebind += gAttributes_Rebind; _gAttributes.GridReorder += gAttributes_Reorder; _gAttributes.ShowActionsInHeader = false; var reorderField = new ReorderField(); _gAttributes.Columns.Add(reorderField); var nameField = new BoundField(); nameField.DataField = "Name"; nameField.HeaderText = "Attribute"; _gAttributes.Columns.Add(nameField); var descField = new BoundField(); descField.DataField = "Description"; descField.HeaderText = "Description"; _gAttributes.Columns.Add(descField); var fieldTypeField = new BoundField(); fieldTypeField.DataField = "FieldType"; fieldTypeField.HeaderText = "Field Type"; _gAttributes.Columns.Add(fieldTypeField); var reqField = new BoolField(); reqField.DataField = "IsRequired"; reqField.HeaderText = "Required"; _gAttributes.Columns.Add(reqField); var editField = new EditField(); editField.Click += gAttributes_Edit; _gAttributes.Columns.Add(editField); var delField = new DeleteField(); delField.Click += gAttributes_Delete; _gAttributes.Columns.Add(delField); }
/// <summary> /// When implemented by a class, defines the <see cref="T:System.Web.UI.Control"/> object that child controls and templates belong to. These child controls are in turn defined within an inline template. /// </summary> /// <param name="container">The <see cref="T:System.Web.UI.Control"/> object to contain the instances of controls from the inline template.</param> public void InstantiateIn( Control container ) { DataControlFieldCell cell = container as DataControlFieldCell; if ( cell != null ) { EditField editField = cell.ContainingField as EditField; ParentGrid = editField.ParentGrid; LinkButton lbEdit = new LinkButton(); lbEdit.CausesValidation = false; lbEdit.CssClass = "btn btn-default btn-sm"; lbEdit.ToolTip = editField.ToolTip; HtmlGenericControl buttonIcon = new HtmlGenericControl( "i" ); buttonIcon.Attributes.Add("class", editField.IconCssClass); lbEdit.Controls.Add( buttonIcon ); lbEdit.Click += lbEdit_Click; cell.Controls.Add( lbEdit ); } }
/// <summary> /// Initializes a new instance of the <see cref="GridActions" /> class. /// </summary> /// <param name="parentGrid">The parent grid.</param> public GridActions( Grid parentGrid ) { _parentGrid = parentGrid; _customActions = new List<Control>(); }
/// <summary> /// When implemented by a class, defines the <see cref="T:System.Web.UI.Control"/> object that child controls and templates belong to. These child controls are in turn defined within an inline template. /// </summary> /// <param name="container">The <see cref="T:System.Web.UI.Control"/> object to contain the instances of controls from the inline template.</param> public void InstantiateIn( Control container ) { DataControlFieldCell cell = container as DataControlFieldCell; if ( cell != null ) { LinkButtonField linkButtonField = cell.ContainingField as LinkButtonField; ParentGrid = linkButtonField.ParentGrid; LinkButton linkButton = new LinkButton(); linkButton.CausesValidation = false; linkButton.CssClass = linkButtonField.CssClass; linkButton.Text = linkButtonField.Text; linkButton.Click += linkButton_Click; // make sure button is registered for async postback (needed just in case the grid was created at runtime) var sm = ScriptManager.GetCurrent( this.ParentGrid.Page ); sm.RegisterAsyncPostBackControl( linkButton ); cell.Controls.Add( linkButton ); } }
/// <summary> /// When implemented by a class, defines the <see cref="T:System.Web.UI.Control"/> object that child controls and templates belong to. These child controls are in turn defined within an inline template. /// </summary> /// <param name="container">The <see cref="T:System.Web.UI.Control"/> object to contain the instances of controls from the inline template.</param> public void InstantiateIn( Control container ) { DataControlFieldCell cell = container as DataControlFieldCell; if ( cell != null ) { EditField editField = cell.ContainingField as EditField; ParentGrid = editField.ParentGrid; LinkButton lbEdit = new LinkButton(); lbEdit.ToolTip = "Edit"; lbEdit.Click += lbEdit_Click; cell.Controls.Add( lbEdit ); } }
/// <summary> /// When implemented by a class, defines the <see cref="T:System.Web.UI.Control"/> object that child controls and templates belong to. These child controls are in turn defined within an inline template. /// </summary> /// <param name="container">The <see cref="T:System.Web.UI.Control"/> object to contain the instances of controls from the inline template.</param> public void InstantiateIn( Control container ) { DataControlFieldCell cell = container as DataControlFieldCell; if ( cell != null ) { DeleteField deleteField = cell.ContainingField as DeleteField; ParentGrid = deleteField.ParentGrid; LinkButton lbDelete = new LinkButton(); lbDelete.ToolTip = "Delete"; lbDelete.Click += lbDelete_Click; lbDelete.DataBinding += lbDelete_DataBinding; lbDelete.PreRender += lbDelete_PreRender; cell.Controls.Add( lbDelete ); } }
private void SetRecipients( Panel pnl, HtmlAnchor htmlAnchor, Literal literalControl, Grid grid, IQueryable<CommunicationRecipient> qryRecipients ) { pnl.CssClass = pnlOpened.Visible ? "col-md-2-10 margin-b-md" : "col-md-3 margin-b-md"; int count = qryRecipients.Count(); if ( count <= 0 ) { htmlAnchor.Attributes["disabled"] = "disabled"; } else { htmlAnchor.Attributes.Remove( "disabled" ); } literalControl.Text = count.ToString( "N0" ); var sortProperty = grid.SortProperty; if ( sortProperty != null ) { qryRecipients = qryRecipients.AsQueryable().Sort( sortProperty ); } else { qryRecipients = qryRecipients.OrderBy( r => r.PersonAlias.Person.LastName ).ThenBy( r => r.PersonAlias.Person.NickName ); } grid.SetLinqDataSource( qryRecipients ); grid.DataBind(); }
/// <summary> /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering. /// </summary> protected override void CreateChildControls() { Controls.Clear(); _hfExpanded = new HiddenFieldWithClass(); Controls.Add( _hfExpanded ); _hfExpanded.ID = this.ID + "_hfExpanded"; _hfExpanded.CssClass = "filter-expanded"; _hfExpanded.Value = "False"; _hfFormGuid = new HiddenField(); Controls.Add( _hfFormGuid ); _hfFormGuid.ID = this.ID + "_hfFormGuid"; _hfFormId = new HiddenField(); Controls.Add( _hfFormId ); _hfFormId.ID = this.ID + "_hfFormId"; _lblFormName = new Label(); Controls.Add( _lblFormName ); _lblFormName.ClientIDMode = ClientIDMode.Static; _lblFormName.ID = this.ID + "_lblFormName"; _lbDeleteForm = new LinkButton(); Controls.Add( _lbDeleteForm ); _lbDeleteForm.CausesValidation = false; _lbDeleteForm.ID = this.ID + "_lbDeleteForm"; _lbDeleteForm.CssClass = "btn btn-xs btn-danger js-activity-delete"; _lbDeleteForm.Click += lbDeleteForm_Click; _lbDeleteForm.Controls.Add( new LiteralControl { Text = "<i class='fa fa-times'></i>" } ); _tbFormName = new RockTextBox(); Controls.Add( _tbFormName ); _tbFormName.ID = this.ID + "_tbFormName"; _tbFormName.Label = "Form Name"; _tbFormName.Required = true; _tbFormName.Attributes["onblur"] = string.Format( "javascript: $('#{0}').text($(this).val());", _lblFormName.ID ); _gFields = new Grid(); Controls.Add( _gFields ); _gFields.ID = this.ID + "_gFields"; _gFields.AllowPaging = false; _gFields.DisplayType = GridDisplayType.Light; _gFields.RowItemText = "Field"; _gFields.AddCssClass( "field-grid" ); _gFields.DataKeyNames = new string[] { "Guid" }; _gFields.Actions.ShowAdd = true; _gFields.Actions.AddClick += gFields_Add; _gFields.GridRebind += gFields_Rebind; _gFields.GridReorder += gFields_Reorder; var reorderField = new ReorderField(); _gFields.Columns.Add( reorderField ); var nameField = new BoundField(); nameField.DataField = "Name"; nameField.HeaderText = "Field"; _gFields.Columns.Add( nameField ); var sourceField = new EnumField(); sourceField.DataField = "FieldSource"; sourceField.HeaderText = "Source"; _gFields.Columns.Add( sourceField ); var typeField = new FieldTypeField(); typeField.DataField = "FieldType"; typeField.HeaderText = "Type"; _gFields.Columns.Add( typeField ); var isInternalField = new BoolField(); isInternalField.DataField = "IsInternal"; isInternalField.HeaderText = "Internal"; _gFields.Columns.Add( isInternalField ); var isSharedValueField = new BoolField(); isSharedValueField.DataField = "IsSharedValue"; isSharedValueField.HeaderText = "Common"; _gFields.Columns.Add( isSharedValueField ); var showCurrentValueField = new BoolField(); showCurrentValueField.DataField = "ShowCurrentValue"; showCurrentValueField.HeaderText = "Use Current Value"; _gFields.Columns.Add( showCurrentValueField ); var isRequiredField = new BoolField(); isRequiredField.DataField = "IsRequired"; isRequiredField.HeaderText = "Required"; _gFields.Columns.Add( isRequiredField ); var isGridField = new BoolField(); isGridField.DataField = "IsGridField"; isGridField.HeaderText = "Show on Grid"; _gFields.Columns.Add( isGridField ); var editField = new EditField(); editField.Click += gFields_Edit; _gFields.Columns.Add( editField ); var delField = new DeleteField(); delField.Click += gFields_Delete; _gFields.Columns.Add( delField ); }
private void CreateGrids( RockContext rockContext ) { if ( ContentChannels.Any() ) { this.Visible = true; // TODO: security bool canEdit = true; phContentChannelGrids.Controls.Clear(); foreach ( var contentChannel in ContentChannels ) { var pwItems = new PanelWidget(); phContentChannelGrids.Controls.Add( pwItems ); pwItems.ID = string.Format( "pwItems_{0}", contentChannel.Id ); pwItems.Title = contentChannel.Name; pwItems.Expanded = ExpandedPanels.Contains( contentChannel.Id ); var divItems = new HtmlGenericControl( "div" ); pwItems.Controls.Add( divItems ); divItems.ID = string.Format( "divItems_{0}", contentChannel.Id ); divItems.AddCssClass( "grid" ); divItems.AddCssClass( "grid-panel" ); Grid gItems = new Grid(); divItems.Controls.Add( gItems ); gItems.ID = string.Format( "gItems_{0}", contentChannel.Id ); gItems.DataKeyNames = new string[] { "Id" }; gItems.EmptyDataText = "No Items Found"; gItems.RowItemText = "Item"; gItems.AllowSorting = true; gItems.Actions.ShowAdd = canEdit; gItems.IsDeleteEnabled = canEdit; gItems.Actions.AddClick += gItems_Add; gItems.RowSelected += gItems_Edit; gItems.GridRebind += gItems_GridRebind; gItems.Columns.Add( new RockBoundField { DataField = "Title", HeaderText = "Title", SortExpression = "Title" } ); gItems.Columns.Add( new DateTimeField { DataField = "StartDateTime", HeaderText = contentChannel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ? "Start" : "Active", SortExpression = "StartDateTime" } ); if ( contentChannel.ContentChannelType.DateRangeType == ContentChannelDateType.DateRange ) { gItems.Columns.Add( new DateTimeField { DataField = "ExpireDateTime", HeaderText = "Expire", SortExpression = "ExpireDateTime" } ); } if ( !contentChannel.ContentChannelType.DisablePriority ) { var priorityField = new RockBoundField { DataField = "Priority", HeaderText = "Priority", SortExpression = "Priority", DataFormatString = "{0:N0}", }; priorityField.ItemStyle.HorizontalAlign = HorizontalAlign.Right; gItems.Columns.Add( priorityField ); } // Add attribute columns int entityTypeId = EntityTypeCache.Read( typeof( Rock.Model.ContentChannelItem ) ).Id; string qualifier = contentChannel.ContentChannelTypeId.ToString(); foreach ( var attribute in new AttributeService( rockContext ).Queryable() .Where( a => a.EntityTypeId == entityTypeId && a.IsGridColumn && a.EntityTypeQualifierColumn.Equals( "ContentChannelTypeId", StringComparison.OrdinalIgnoreCase ) && a.EntityTypeQualifierValue.Equals( qualifier ) ) .OrderBy( a => a.Order ) .ThenBy( a => a.Name ) ) { string dataFieldExpression = attribute.Key; bool columnExists = gItems.Columns.OfType<AttributeField>().FirstOrDefault( a => a.DataField.Equals( dataFieldExpression ) ) != null; if ( !columnExists ) { AttributeField boundField = new AttributeField(); boundField.DataField = dataFieldExpression; boundField.HeaderText = attribute.Name; boundField.SortExpression = string.Empty; var attributeCache = Rock.Web.Cache.AttributeCache.Read( attribute.Id ); if ( attributeCache != null ) { boundField.ItemStyle.HorizontalAlign = attributeCache.FieldType.Field.AlignValue; } gItems.Columns.Add( boundField ); } } if ( contentChannel.RequiresApproval ) { var statusField = new BoundField(); gItems.Columns.Add( statusField ); statusField.DataField = "Status"; statusField.HeaderText = "Status"; statusField.SortExpression = "Status"; statusField.HtmlEncode = false; } var deleteField = new DeleteField(); gItems.Columns.Add( deleteField ); deleteField.Click += gItems_Delete; } } else { this.Visible = false; } }
/// <summary> /// Creates the locations grid. /// </summary> private void CreateLocationsGrid() { _gLocations = new Grid(); // make the ID static so we can handle Postbacks from the Add and Delete actions _gLocations.ClientIDMode = System.Web.UI.ClientIDMode.Static; _gLocations.ID = this.ClientID + "_gCheckinLabels"; _gLocations.DisplayType = GridDisplayType.Light; _gLocations.ShowActionRow = true; _gLocations.RowItemText = "Location"; _gLocations.Actions.ShowAdd = true; //// Handle AddClick manually in OnLoad() _gLocations.Actions.AddClick += AddLocation_Click; _gLocations.DataKeyNames = new string[] { "LocationId" }; _gLocations.Columns.Add( new BoundField { DataField = "Name", HeaderText = "Name" } ); DeleteField deleteField = new DeleteField(); //// handle manually in OnLoad() deleteField.Click += DeleteLocation_Click; _gLocations.Columns.Add( deleteField ); Controls.Add( _gLocations ); }
/// <summary> /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering. /// </summary> protected override void CreateChildControls() { Controls.Clear(); _hfExpanded = new HiddenFieldWithClass(); Controls.Add( _hfExpanded ); _hfExpanded.ID = this.ID + "_hfExpanded"; _hfExpanded.CssClass = "filter-expanded"; _hfExpanded.Value = "False"; _hfActivityTypeGuid = new HiddenField(); Controls.Add( _hfActivityTypeGuid ); _hfActivityTypeGuid.ID = this.ID + "_hfActivityTypeGuid"; _lblActivityTypeName = new Label(); Controls.Add( _lblActivityTypeName ); _lblActivityTypeName.ClientIDMode = ClientIDMode.Static; _lblActivityTypeName.ID = this.ID + "_lblActivityTypeName"; _lblActivityTypeDescription = new Label(); Controls.Add( _lblActivityTypeDescription ); _lblActivityTypeDescription.ClientIDMode = ClientIDMode.Static; _lblActivityTypeDescription.ID = this.ID + "_lblActivityTypeDescription"; _lblInactive = new Label(); Controls.Add( _lblInactive ); _lblInactive.ClientIDMode = ClientIDMode.Static; _lblInactive.ID = this.ID + "_lblInactive"; _lblInactive.CssClass = "pull-right"; _lblInactive.Text = "<span class='label label-danger'>Inactive</span>"; _lbDeleteActivityType = new LinkButton(); Controls.Add( _lbDeleteActivityType ); _lbDeleteActivityType.CausesValidation = false; _lbDeleteActivityType.ID = this.ID + "_lbDeleteActivityType"; _lbDeleteActivityType.CssClass = "btn btn-xs btn-danger js-activity-delete"; _lbDeleteActivityType.Click += lbDeleteActivityType_Click; _lbDeleteActivityType.Controls.Add( new LiteralControl { Text = "<i class='fa fa-times'></i>" } ); _sbSecurity = new SecurityButton(); Controls.Add( _sbSecurity ); _sbSecurity.ID = this.ID + "_sbSecurity"; _sbSecurity.Attributes["class"] = "btn btn-security btn-xs security pull-right"; _sbSecurity.EntityTypeId = EntityTypeCache.Read( typeof( Rock.Model.WorkflowActivityType ) ).Id; _cbActivityTypeIsActive = new RockCheckBox { Text = "Active" }; Controls.Add( _cbActivityTypeIsActive ); _cbActivityTypeIsActive.ID = this.ID + "_cbActivityTypeIsActive"; string checkboxScriptFormat = @" javascript: if ($(this).is(':checked')) {{ $('#{0}').hide(); $('#{1}').removeClass('workflow-activity-inactive'); }} else {{ $('#{0}').show(); $('#{1}').addClass('workflow-activity-inactive'); }} "; _cbActivityTypeIsActive.InputAttributes.Add( "onclick", string.Format( checkboxScriptFormat, _lblInactive.ID, this.ID + "_section" ) ); _tbActivityTypeName = new RockTextBox(); Controls.Add( _tbActivityTypeName ); _tbActivityTypeName.ID = this.ID + "_tbActivityTypeName"; _tbActivityTypeName.Label = "Name"; _tbActivityTypeName.Required = true; _tbActivityTypeName.Attributes["onblur"] = string.Format( "javascript: $('#{0}').text($(this).val());", _lblActivityTypeName.ID ); _tbActivityTypeDescription = new RockTextBox(); Controls.Add( _tbActivityTypeDescription ); _tbActivityTypeDescription.ID = this.ID + "_tbActivityTypeDescription"; _tbActivityTypeDescription.Label = "Description"; _tbActivityTypeDescription.TextMode = TextBoxMode.MultiLine; _tbActivityTypeDescription.Rows = 2; _tbActivityTypeDescription.Attributes["onblur"] = string.Format( "javascript: $('#{0}').text($(this).val());", _lblActivityTypeDescription.ID ); _cbActivityTypeIsActivatedWithWorkflow = new RockCheckBox { Text = "Activated with Workflow" }; Controls.Add( _cbActivityTypeIsActivatedWithWorkflow ); _cbActivityTypeIsActivatedWithWorkflow.ID = this.ID + "_cbActivityTypeIsActivatedWithWorkflow"; checkboxScriptFormat = @" javascript: if ($(this).is(':checked')) {{ $('#{0}').addClass('activated-with-workflow'); }} else {{ $('#{0}').removeClass('activated-with-workflow'); }} "; _cbActivityTypeIsActivatedWithWorkflow.InputAttributes.Add( "onclick", string.Format( checkboxScriptFormat, this.ID + "_section" ) ); _lbAddActionType = new LinkButton(); Controls.Add( _lbAddActionType ); _lbAddActionType.ID = this.ID + "_lbAddAction"; _lbAddActionType.CssClass = "btn btn-xs btn-action"; _lbAddActionType.Click += lbAddActionType_Click; _lbAddActionType.CausesValidation = false; _lbAddActionType.Controls.Add( new LiteralControl { Text = "<i class='fa fa-plus'></i> Add Action" } ); _pwAttributes = new PanelWidget(); Controls.Add( _pwAttributes ); _pwAttributes.ID = this.ID + "_pwAttributes"; _pwAttributes.Title = "Activity Attributes"; _pwAttributes.CssClass = "attribute-panel"; _gAttributes = new Grid(); _pwAttributes.Controls.Add( _gAttributes ); _gAttributes.ID = this.ID + "_gAttributes"; _gAttributes.AllowPaging = false; _gAttributes.DisplayType = GridDisplayType.Light; _gAttributes.RowItemText = "Activity Attribute"; _gAttributes.AddCssClass( "attribute-grid" ); _gAttributes.DataKeyNames = new string[] { "Guid" }; _gAttributes.Actions.ShowAdd = true; _gAttributes.Actions.AddClick += gAttributes_Add; _gAttributes.GridRebind += gAttributes_Rebind; _gAttributes.GridReorder += gAttributes_Reorder; var reorderField = new ReorderField(); _gAttributes.Columns.Add( reorderField ); var nameField = new BoundField(); nameField.DataField = "Name"; nameField.HeaderText = "Attribute"; _gAttributes.Columns.Add( nameField ); var descField = new BoundField(); descField.DataField = "Description"; descField.HeaderText = "Description"; _gAttributes.Columns.Add( descField ); var fieldTypeField = new BoundField(); fieldTypeField.DataField = "FieldType"; fieldTypeField.HeaderText = "Field Type"; _gAttributes.Columns.Add( fieldTypeField ); var reqField = new BoolField(); reqField.DataField = "IsRequired"; reqField.HeaderText = "Required"; _gAttributes.Columns.Add( reqField ); var editField = new EditField(); editField.Click += gAttributes_Edit; _gAttributes.Columns.Add( editField ); var delField = new DeleteField(); delField.Click += gAttributes_Delete; _gAttributes.Columns.Add( delField ); }
/// <summary> /// Builds the controls. /// </summary> /// <param name="setData">if set to <c>true</c> [set data].</param> private void BuildControls( bool setData ) { var showGridFilterControls = GetAttributeValue( "ShowGridFilter" ).AsBoolean(); string errorMessage = string.Empty; // get just the schema of the data until we actually need the data var dataSetSchema = GetData( out errorMessage, true ); if ( !string.IsNullOrWhiteSpace( errorMessage ) ) { phContent.Visible = false; nbError.Text = errorMessage; nbError.Visible = true; } else { phContent.Controls.Clear(); var mergeFields = GetDynamicDataMergeFields(); if ( dataSetSchema != null ) { string formattedOutput = GetAttributeValue( "FormattedOutput" ); // load merge objects if needed by either for formatted output OR page title if ( !string.IsNullOrWhiteSpace( GetAttributeValue( "PageTitleLava" ) ) || !string.IsNullOrWhiteSpace( formattedOutput ) ) { int i = 1; // Formatted output needs all the rows, so get the data regardless of the setData parameter var dataSet = GetData( out errorMessage); foreach ( DataTable dataTable in dataSet.Tables ) { var dropRows = new List<DataRowDrop>(); foreach ( DataRow row in dataTable.Rows ) { dropRows.Add( new DataRowDrop( row ) ); } if ( dataSet.Tables.Count > 1 ) { var tableField = new Dictionary<string, object>(); tableField.Add( "rows", dropRows ); mergeFields.Add( "table" + i.ToString(), tableField ); } else { mergeFields.Add( "rows", dropRows ); } i++; } } // set page title if ( !string.IsNullOrWhiteSpace( GetAttributeValue( "PageTitleLava" ) ) ) { string title = GetAttributeValue( "PageTitleLava" ).ResolveMergeFields( mergeFields ); RockPage.BrowserTitle = title; RockPage.PageTitle = title; RockPage.Header.Title = title; } if ( string.IsNullOrWhiteSpace( formattedOutput ) ) { bool personReport = GetAttributeValue( "PersonReport" ).AsBoolean(); int tableId = 0; DataSet dataSet; if ( setData == false ) { dataSet = dataSetSchema; } else { dataSet = GetData( out errorMessage ); } foreach ( DataTable dataTable in dataSet.Tables ) { var div = new HtmlGenericControl( "div" ); div.AddCssClass( "grid" ); if ( GetAttributeValue( "PaneledGrid" ).AsBoolean() ) { div.AddCssClass( "grid-panel" ); } phContent.Controls.Add( div ); GridFilter = new GridFilter() { ID = string.Format("gfFilter{0}", tableId ) }; div.Controls.Add( GridFilter ); GridFilter.ApplyFilterClick += ApplyFilterClick; GridFilter.DisplayFilterValue += DisplayFilterValue; GridFilter.Visible = showGridFilterControls && (dataSet.Tables.Count == 1); var grid = new Grid(); div.Controls.Add( grid ); grid.ID = string.Format( "dynamic_data_{0}", tableId++ ); grid.AllowSorting = true; grid.EmptyDataText = "No Results"; grid.Actions.ShowCommunicate = GetAttributeValue( "ShowCommunicate" ).AsBoolean(); grid.Actions.ShowMergePerson = GetAttributeValue( "ShowMergePerson" ).AsBoolean(); grid.Actions.ShowBulkUpdate = GetAttributeValue( "ShowBulkUpdate" ).AsBoolean(); grid.Actions.ShowExcelExport = GetAttributeValue( "ShowExcelExport" ).AsBoolean(); grid.Actions.ShowMergeTemplate = GetAttributeValue( "ShowMergeTemplate" ).AsBoolean(); grid.GridRebind += gReport_GridRebind; grid.RowSelected += gReport_RowSelected; if ( personReport ) { grid.PersonIdField = "Id"; } else { grid.PersonIdField = null; } grid.CommunicateMergeFields = GetAttributeValue( "MergeFields" ).SplitDelimitedValues().ToList<string>(); AddGridColumns( grid, dataTable ); SetDataKeyNames( grid, dataTable ); if ( setData ) { FilterTable( grid, dataTable ); SortTable( grid, dataTable ); grid.DataSource = dataTable; if ( personReport) { grid.EntityTypeId = EntityTypeCache.GetId<Person>(); } grid.DataBind(); } } } else { phContent.Controls.Add( new LiteralControl( formattedOutput.ResolveMergeFields( mergeFields ) ) ); } } phContent.Visible = true; nbError.Visible = false; } }
/// <summary> /// Performs basic instance initialization for a data control field. /// </summary> /// <param name="sortingEnabled">A value that indicates whether the control supports the sorting of columns of data.</param> /// <param name="control">The data control that owns the <see cref="T:System.Web.UI.WebControls.DataControlField"/>.</param> /// <returns> /// Always returns false. /// </returns> public override bool Initialize( bool sortingEnabled, Control control ) { ToggleFieldTemplate toggleFieldTemplate = new ToggleFieldTemplate(); toggleFieldTemplate.CheckedChanged += toggleFieldTemplate_CheckedChanged; this.ItemTemplate = toggleFieldTemplate; this.ParentGrid = control as Grid; return base.Initialize( sortingEnabled, control ); }
/// <summary> /// Sets the data key names. /// </summary> private void SetDataKeyNames( Grid grid, DataTable dataTable ) { string urlMask = GetAttributeValue( "UrlMask" ); if ( !string.IsNullOrWhiteSpace( urlMask ) ) { Regex pattern = new Regex( @"\{[\w\s]+\}" ); var matches = pattern.Matches( urlMask ); if ( matches.Count > 0 ) { var keyNames = new List<string>(); for ( int i = 0; i < matches.Count; i++ ) { string colName = matches[i].Value.TrimStart( '{' ).TrimEnd( '}' ); if ( dataTable.Columns.Contains( colName ) ) { keyNames.Add( colName ); } } grid.DataKeyNames = keyNames.ToArray(); } } else { if ( dataTable.Columns.Contains( "Id" ) ) { grid.DataKeyNames = new string[1] { "Id" }; } } }
/// <summary> /// When implemented by a class, defines the <see cref="T:System.Web.UI.Control"/> /// object that child controls and templates belong to. These child controls are in /// turn defined within an inline template. /// </summary> /// <param name="container">The <see cref="T:System.Web.UI.Control"/> object to contain the instances of controls from the inline template.</param> public void InstantiateIn( Control container ) { DataControlFieldCell cell = container as DataControlFieldCell; if ( cell != null ) { ToggleField toggleField = cell.ContainingField as ToggleField; ParentGrid = toggleField.ParentGrid; DataField = toggleField.DataField; bool isEnabled = false; bool.TryParse(toggleField.Enabled, out isEnabled ); Enabled = isEnabled; Toggle toggle = new Toggle(); toggle.OnText = toggleField.OnText; toggle.OffText = toggleField.OffText; toggle.OnCssClass = toggleField.OnCssClass; toggle.OffCssClass = toggleField.OffCssClass; //toggle.EnableViewState = true; // TODO remove if unnecessary toggle.ActiveButtonCssClass = toggleField.ActiveButtonCssClass; toggle.ButtonSizeCssClass = toggleField.ButtonSizeCssClass; toggle.CheckedChanged += toggle_CheckedChanged; toggle.DataBinding += toggle_DataBinding; toggle.PreRender += toggle_PreRender; cell.Controls.Add( toggle ); } }
private bool BindGrid( Grid grid, DataView dataView ) { var errors = new List<string>(); grid.DataSource = dataView.BindGrid( grid, out errors, true ); if ( grid.DataSource != null ) { if ( errors.Any() ) { nbEditModeMessage.Text = "INFO: There was a problem with one or more of the filters for this data view...<br/><br/> " + errors.AsDelimited( "<br/>" ); } if ( dataView.EntityTypeId.HasValue ) { grid.RowItemText = EntityTypeCache.Read( dataView.EntityTypeId.Value ).FriendlyName; } grid.DataBind(); return true; } return false; }
private void ClearGrid(Grid grid ) { // Remove any of the dynamic person fields var dynamicColumns = new List<string> { "PersonAlias.Person.BirthDate", }; foreach ( var column in grid.Columns .OfType<BoundField>() .Where( c => dynamicColumns.Contains( c.DataField ) ) .ToList() ) { grid.Columns.Remove( column ); } // Remove any of the dynamic attribute fields foreach ( var column in grid.Columns .OfType<AttributeField>() .ToList() ) { grid.Columns.Remove( column ); } // Remove the fees field foreach ( var column in grid.Columns .OfType<TemplateField>() .Where( c => c.HeaderText == "Fees" ) .ToList() ) { grid.Columns.Remove( column ); } // Remove the delete field foreach ( var column in grid.Columns .OfType<DeleteField>() .ToList() ) { grid.Columns.Remove( column ); } // Remove the delete field foreach ( var column in grid.Columns .OfType<GroupPickerField>() .ToList() ) { grid.Columns.Remove( column ); } }