protected void UniGrid_OnBeforeDataReload() { if ((usScopes.UniGrid.GridView.Columns.Count > 0) && !usScopes.UniGrid.NamedColumns.ContainsKey("SiteName")) { // Add additional site column ExtendedBoundField field = new ExtendedBoundField(); field.HeaderText = GetString("general.sitename"); field.DataField = "ScopeSiteID"; field.ExternalSourceName = "#sitename"; field.ItemStyle.Wrap = false; field.HeaderStyle.Width = new Unit("100%"); field.OnExternalDataBound += usScopes.UniGrid.RaiseExternalDataBound; usScopes.UniGrid.GridView.Columns.Add(field); usScopes.UniGrid.NamedColumns.Add("SiteName", field); // Clear width for item name column usScopes.UniGrid.GridView.Columns[1].HeaderStyle.Width = new Unit(); } }
/// <summary> /// Load single column definition. /// </summary> /// <param name="column">Column to use</param> /// <param name="filterTable">Table for filter</param> private void LoadColumnDefinition(Column column, Table filterTable) { DataControlField field = null; string cssClass = column.CssClass; string columnCaption = null; // Process the column type Hyperlink or BoundColumn based on the parameters if ((column.HRef != null) || (column.ExternalSourceName != null) || (column.Localize) || (column.Icon != null) || (column.Tooltip != null) || (column.Action != null) || (column.Style != null) || (column.MaxLength > 0)) { ExtendedBoundField linkColumn = new ExtendedBoundField(); field = linkColumn; // Attribute "source" if (column.Source != null) { linkColumn.DataField = column.Source; if (column.AllowSorting) { if (!String.IsNullOrEmpty(column.Sort)) { linkColumn.SortExpression = column.Sort; } else if (column.Source.ToLower() != ExtendedBoundField.ALL_DATA.ToLower()) { linkColumn.SortExpression = column.Source; } } } // Action parameters if (column.Action != null) { linkColumn.Action = column.Action; // Action parameters if (column.CommandArgument != null) { linkColumn.CommandArgument = column.CommandArgument; } } // Action parameters if (column.Parameters != null) { linkColumn.ActionParameters = column.Parameters; } // Navigate URL if (column.HRef != null) { linkColumn.NavigateUrl = column.HRef; } // External source if (column.ExternalSourceName != null) { linkColumn.ExternalSourceName = column.ExternalSourceName; linkColumn.OnExternalDataBound += RaiseExternalDataBound; } // Localize strings? linkColumn.LocalizeStrings = column.Localize; // Style if (column.Style != null) { linkColumn.Style = column.Style; } // Class name if (cssClass != null) { linkColumn.HeaderStyle.CssClass += " " + cssClass; linkColumn.ItemStyle.CssClass += " " + cssClass; linkColumn.FooterStyle.CssClass += " " + cssClass; } // Icon if (column.Icon != null) { if (linkColumn.DataField == "") { linkColumn.DataField = ExtendedBoundField.ALL_DATA; } linkColumn.Icon = GetActionImage(column.Icon); } // Max length if (column.MaxLength > 0) { linkColumn.MaxLength = column.MaxLength; } // Process "tooltip" node ColumnTooltip tooltip = column.Tooltip; if (tooltip != null) { // If there is some tooltip register TooltipScript if ((tooltip.Source != null) || (tooltip.ExternalSourceName != null)) { ScriptHelper.RegisterTooltip(Page); } // Tooltip source if (tooltip.Source != null) { linkColumn.TooltipSourceName = tooltip.Source; } // Tooltip external source if (tooltip.ExternalSourceName != null) { linkColumn.TooltipExternalSourceName = tooltip.ExternalSourceName; } // Tooltip width if (tooltip.Width != null) { linkColumn.TooltipWidth = tooltip.Width; } // Encode tooltip linkColumn.TooltipEncode = tooltip.Encode; } } else { BoundField userColumn = new BoundField(); // Custom column of the grid view field = userColumn; // Attribute "source" if (column.Source != null) { userColumn.DataField = column.Source; // Allow sorting if (column.AllowSorting) { if (column.Source.ToLower() != ExtendedBoundField.ALL_DATA.ToLower()) { userColumn.SortExpression = column.Source; } else if (column.Sort != null) { userColumn.SortExpression = column.Sort; } } } } if (!IsLiveSite) { field.HeaderStyle.CssClass = "NW"; } else { field.HeaderStyle.Wrap = false; } // Column name if (column.Name != null) { NamedColumns[column.Name] = field; } // Caption if (column.Caption != null) { columnCaption = GetString(ResHelper.GetResourceName(column.Caption)); field.HeaderText = columnCaption; } // Width if (column.Width != null) { if (GridView.ShowHeader) { field.HeaderStyle.Width = new Unit(column.Width); } else { field.ItemStyle.Width = new Unit(column.Width); } } // Visible field.Visible = column.Visible; // Is text? if (column.IsText && (column.Source != null)) { TextColumns.Add(column.Source); } // Wrap? if (!column.Wrap) { if (!IsLiveSite) { field.ItemStyle.CssClass = "NW"; } else { field.ItemStyle.Wrap = false; } } // Class name if (cssClass != null) { field.HeaderStyle.CssClass += " " + cssClass; field.ItemStyle.CssClass += " " + cssClass; field.FooterStyle.CssClass += " " + cssClass; } // Process "filter" node if (displayFilter) { // Filter ColumnFilter filter = column.Filter; if (filter != null) { object option = null; object value = null; // Filter via query string if (FilterByQueryString) { if (String.IsNullOrEmpty(filter.Path)) { string values = QueryHelper.GetString(column.Source, null); if (!string.IsNullOrEmpty(values)) { string[] pair = values.Split(';'); option = pair[0]; value = pair[1]; } } else { value = QueryHelper.GetString(column.Source, null); } } string filterSource = filter.Source ?? column.Source; // Add the filter field AddFilterField(filter.Type, filter.Path, filter.Format, filterSource, columnCaption, filterTable, option, value, filter.Size); } } // Add custom column to gridview UniGridView.Columns.Add(field); }
/// <summary> /// Load single column definition. /// </summary> /// <param name="column">Column to use</param> /// <param name="filterWrapperControl">Wrapper control for filter</param> private void LoadColumnDefinition(Column column, Control filterWrapperControl) { DataControlField field; string cssClass = column.CssClass; string columnCaption = null; // Process the column type Hyperlink or BoundColumn based on the parameters if ((column.Href != null) || (column.ExternalSourceName != null) || (column.Localize) || (column.Icon != null) || (column.Tooltip != null) || (column.Action != null) || (column.Style != null) || (column.MaxLength > 0)) { ExtendedBoundField linkColumn = new ExtendedBoundField(); field = linkColumn; // Attribute "source" if (column.Source != null) { linkColumn.DataField = column.Source; // Allow sorting if ((column.AllowSorting) && ((GridOptions == null) || GridOptions.AllowSorting)) { if (!String.IsNullOrEmpty(column.Sort)) { linkColumn.SortExpression = column.Sort; } else if (column.Source.ToLowerCSafe() != ExtendedBoundField.ALL_DATA.ToLowerCSafe()) { linkColumn.SortExpression = column.Source; } } } // Action parameters if (column.Action != null) { linkColumn.Action = column.Action; // Action parameters if (column.CommandArgument != null) { linkColumn.CommandArgument = column.CommandArgument; } } // Action parameters if (column.Parameters != null) { linkColumn.ActionParameters = column.Parameters; } // Navigate URL if (column.Href != null) { linkColumn.NavigateUrl = column.Href; } // External source if (column.ExternalSourceName != null) { linkColumn.ExternalSourceName = column.ExternalSourceName; linkColumn.OnExternalDataBound += RaiseExternalDataBound; } // Localize strings? linkColumn.LocalizeStrings = column.Localize; // Style if (column.Style != null) { linkColumn.Style = column.Style; } // Icon if (column.Icon != null) { if (String.IsNullOrEmpty(linkColumn.DataField)) { linkColumn.DataField = ExtendedBoundField.ALL_DATA; } linkColumn.Icon = GetActionImage(column.Icon); } // Max length if (column.MaxLength > 0) { linkColumn.MaxLength = column.MaxLength; } // Process "tooltip" node ColumnTooltip tooltip = column.Tooltip; if (tooltip != null) { // If there is some tooltip register TooltipScript if ((tooltip.Source != null) || (tooltip.ExternalSourceName != null)) { ScriptHelper.RegisterTooltip(Page); } // Tooltip source if (tooltip.Source != null) { linkColumn.TooltipSourceName = tooltip.Source; } // Tooltip external source if (tooltip.ExternalSourceName != null) { linkColumn.TooltipExternalSourceName = tooltip.ExternalSourceName; // Ensure external data bound event handler if (string.IsNullOrEmpty(column.ExternalSourceName)) { linkColumn.OnExternalDataBound += RaiseExternalDataBound; } } // Tooltip width if (tooltip.Width != null) { linkColumn.TooltipWidth = tooltip.Width; } // Encode tooltip linkColumn.TooltipEncode = tooltip.Encode; } } else { BoundField userColumn = new BoundField(); // Custom column of the grid view field = userColumn; // Attribute "source" if (column.Source != null) { userColumn.DataField = column.Source; // Allow sorting if ((column.AllowSorting) && ((GridOptions == null) || GridOptions.AllowSorting)) { if (column.Source.ToLowerCSafe() != ExtendedBoundField.ALL_DATA.ToLowerCSafe()) { userColumn.SortExpression = column.Source; } else if (column.Sort != null) { userColumn.SortExpression = column.Sort; } } } } if (IsLiveSite) { field.HeaderStyle.Wrap = false; } // Column name if (column.Name != null) { NamedColumns[column.Name] = field; } // Caption if (column.Caption != null) { columnCaption = GetString(LocalizationHelper.GetResourceName(column.Caption)); field.HeaderText = columnCaption; } // Width if (column.Width != null) { if (GridView.ShowHeader) { field.HeaderStyle.Width = new Unit(column.Width); } else { field.ItemStyle.Width = new Unit(column.Width); } } // Visible field.Visible = column.Visible; // Is text? if (column.IsText && (column.Source != null)) { TextColumns.Add(column.Source); } // Wrap? if (column.Wrap) { field.ItemStyle.CssClass = "wrap-normal"; } else if (IsLiveSite) { field.ItemStyle.Wrap = false; } // Class name if (cssClass != null) { field.HeaderStyle.CssClass = CSSHelper.JoinClasses(field.HeaderStyle.CssClass, cssClass); field.ItemStyle.CssClass = CSSHelper.JoinClasses(field.ItemStyle.CssClass, cssClass); field.FooterStyle.CssClass = CSSHelper.JoinClasses(field.FooterStyle.CssClass, cssClass); } // Process "filter" node if (displayFilter && !mCustomFilterAdded) { // Filter ColumnFilter filter = column.Filter; if (filter != null) { string value = null; // Filter via query string if (FilterByQueryString) { if (String.IsNullOrEmpty(filter.Path)) { string values = QueryHelper.GetString(column.Source, null); if (!string.IsNullOrEmpty(values)) { string[] pair = values.Split(';'); value = pair[1]; } } else { value = QueryHelper.GetString(column.Source, null); } } AddFilterField(filter, column.Source, columnCaption, filterWrapperControl, value); } } // Add custom column to GridView GridView.Columns.Add(field); // Store corresponding field column.Field = field; }