Greetings,
I am trying to move from using UWG to WDG for our default grid (version 2011.1 until we can switch everything from UWG). Previously we created a custom control to make it even easier to add a grid to a page, and I am trying to recreate this functionality with WDG. Below is the code for the UWG version, can anyone help me figure out the WDG version?
public class DDG : UltraWebGrid, IPostBackEventHandler { //public DDG() //{ // gridInit(); //} protected override void OnInit(EventArgs e) { base.OnInit(e); gridInit(); InitializeRow += new InitializeRowEventHandler(DDG_InitializeRow); } private void gridInit() { DisplayLayout.StationaryMargins = StationaryMargins.Header; //DisplayLayout.AllowSortingDefault = AllowSorting.OnClient; DisplayLayout.RowHeightDefault = Unit.Pixel(20); DisplayLayout.RowSizingDefault = AllowSizing.Free; DisplayLayout.SelectTypeRowDefault = SelectType.Single; //DisplayLayout.HeaderClickActionDefault = HeaderClickAction.SortSingle; DisplayLayout.BorderCollapseDefault = BorderCollapse.Separate; DisplayLayout.AllowColSizingDefault = AllowSizing.Free; DisplayLayout.CellPaddingDefault = 1; DisplayLayout.RowSelectorsDefault = RowSelectors.No; DisplayLayout.TableLayout = TableLayout.Fixed; DisplayLayout.CellClickActionDefault = CellClickAction.RowSelect; DisplayLayout.HeaderStyleDefault.Font.Size = FontUnit.Point(8); DisplayLayout.HeaderStyleDefault.Font.Bold = true; DisplayLayout.HeaderStyleDefault.BorderColor = Color.Black; DisplayLayout.HeaderStyleDefault.BorderStyle = BorderStyle.Solid; DisplayLayout.HeaderStyleDefault.ForeColor = Color.FromArgb(0, 0, 153); DisplayLayout.HeaderStyleDefault.BackColor = Color.FromArgb(255, 200, 145); DisplayLayout.HeaderStyleDefault.BorderDetails.ColorTop = Color.White; DisplayLayout.HeaderStyleDefault.BorderDetails.ColorLeft = Color.White; DisplayLayout.HeaderStyleDefault.BorderDetails.WidthLeft = Unit.Pixel(1); DisplayLayout.HeaderStyleDefault.BorderDetails.WidthTop = Unit.Pixel(1); DisplayLayout.RowSelectorStyleDefault.BorderStyle = BorderStyle.Solid; // this.DisplayLayout.FrameStyle.Width=Unit.Percentage(99); DisplayLayout.FrameStyle.Cursor = Cursors.Default; DisplayLayout.FrameStyle.BorderWidth = Unit.Pixel(3); DisplayLayout.FrameStyle.Font.Size = FontUnit.Point(8); DisplayLayout.FrameStyle.Font.Names = new string[] { "Verdana" }; DisplayLayout.FrameStyle.BorderColor = Color.FromArgb(0, 0, 153); DisplayLayout.FrameStyle.BorderStyle = BorderStyle.Solid; DisplayLayout.FrameStyle.ForeColor = Color.White; DisplayLayout.FrameStyle.BackColor = Color.FromArgb(0, 0, 153); // this.DisplayLayout.FrameStyle.Height=Unit.Pixel(400); DisplayLayout.FooterStyleDefault.BorderWidth = Unit.Pixel(1); DisplayLayout.FooterStyleDefault.BorderStyle = BorderStyle.Solid; DisplayLayout.FooterStyleDefault.BackColor = Color.LightGray; DisplayLayout.FooterStyleDefault.BorderDetails.ColorTop = Color.White; DisplayLayout.FooterStyleDefault.BorderDetails.ColorLeft = Color.White; DisplayLayout.FooterStyleDefault.BorderDetails.WidthLeft = Unit.Pixel(1); DisplayLayout.FooterStyleDefault.BorderDetails.WidthTop = Unit.Pixel(1); DisplayLayout.ActivationObject.BorderStyle = BorderStyle.Dotted; DisplayLayout.SelectedRowStyleDefault.ForeColor = Color.Black; DisplayLayout.SelectedRowStyleDefault.Font.Bold = true; DisplayLayout.RowAlternateStyleDefault.BackColor = Color.FromArgb(255, 227, 198); DisplayLayout.RowStyleDefault.BorderWidth = Unit.Pixel(1); DisplayLayout.RowStyleDefault.BorderColor = Color.Gray; DisplayLayout.RowStyleDefault.BorderStyle = BorderStyle.Solid; DisplayLayout.RowStyleDefault.Font.Size = FontUnit.Point(8); DisplayLayout.RowStyleDefault.ForeColor = Color.Black; DisplayLayout.RowStyleDefault.BackColor = Color.White; DisplayLayout.RowStyleDefault.Padding.Left = Unit.Pixel(3); DisplayLayout.RowStyleDefault.BorderDetails.ColorTop = Color.Gray; DisplayLayout.RowStyleDefault.BorderDetails.ColorLeft = Color.Gray; DisplayLayout.RowStyleDefault.BorderDetails.WidthTop = Unit.Pixel(0); DisplayLayout.RowStyleDefault.BorderDetails.WidthLeft = Unit.Pixel(0); } public override void OnInitializeLayout(UltraGridLayout layout) { base.OnInitializeLayout(layout); if (ShowActionColumn && ActionFields.Count > 0 && !DisplayLayout.Bands[0].Columns.Exists("actions")) { DisplayLayout.Bands[0].Columns.Insert(0, "actions"); DisplayLayout.Bands[0].Columns.FromKey("actions").HeaderText = "Actions"; } } /// <summary> /// Array of strings to identify the key fields for this grid. these fields are returned through DDGRowAction event to identify which row was acted upon /// </summary> public string[] DataKeyFields { get { return (string[])ViewState["DDGDataKeyField"]; } set { ViewState["DDGDataKeyField"] = value; } } public bool ShowActionColumn { get { if (ViewState["ShowActionColumn"] == null) ViewState["ShowActionColumn"] = true; return (bool)ViewState["ShowActionColumn"]; } set { ViewState["ShowActionColumn"] = value; } } public bool UseActionBrackets { get { if (ViewState["UseActionBrackets"] == null) ViewState["UseActionBrackets"] = true; return (bool)ViewState["UseActionBrackets"]; } set { ViewState["UseActionBrackets"] = value; } } private ArrayList _af = new ArrayList(); /// <summary> /// List of actions that can be taken on each row. these words are shown in the grid, and made clickable. when clicked, they fire the /// DDGRowAction event, returning the ActionField word, along with the key for that row /// </summary> public ArrayList ActionFields { get { return _af; } set { _af = value; } } public delegate void DDGRowActionEventHandler(object sender, DDGEventArgs e); public delegate void DDGRowInitEventHandler(object sender, DDGRowInitArgs e); /// <summary> /// contains information on the Row Action that occured. /// "itemIDs" is an array of values that make up the key for the row that was acted upon. values are in same order as DataKeyFields array /// "action" is the ActionField word that was clicked by the user /// </summary> public class DDGEventArgs : EventArgs { private string[] _itemIDs; public string[] itemIDs { get { return _itemIDs; } set { _itemIDs = value; } } private string _action; public string action { get { return _action; } set { _action = value; } } } public class DDGRowInitArgs : EventArgs { public bool enabled = true; public UltraGridRow row; public object data; public string action; public string column = "actions"; public string link; } /// <summary> /// Fires when the user clicks on an ActionField in the action column of the grid /// </summary> public event DDGRowActionEventHandler OnDDGRowAction; public event DDGRowInitEventHandler OnDDGRowInit; private string getKeyString(UltraGridRow row) { string ret = ""; foreach (string fieldname in DataKeyFields) ret += "|" + Convert.ToString(row.Cells.FromKey(fieldname).Value); return ret.TrimStart('|'); } // private string removeHTML(string cleanThis) // { // System.Text.RegularExpressions.Regex rex = new System.Text.RegularExpressions.Regex("<[^>]*>"); // return rex.Replace(cleanThis," "); // } public new void RaisePostBackEvent(string eventArgument) { base.RaisePostBackEvent(eventArgument); string[] args = eventArgument.Split('|'); string eventname = args[0]; DDGEventArgs e = new DDGEventArgs(); e.itemIDs = new string[args.Length - 1]; for (int i = 1; i < args.Length; i++) e.itemIDs[i - 1] = args[i]; e.action = eventname; if (OnDDGRowAction != null) OnDDGRowAction(this, e); } private void DDG_InitializeRow(object sender, RowEventArgs e) { DDGRowInitArgs ex; string field; string key; for (int i = 0; i < ActionFields.Count; i++) { field = (string)ActionFields[i]; ex = new DDGRowInitArgs(); ex.row = e.Row; ex.data = e.Data; ex.action = field; ex.link = field; if (OnDDGRowInit != null) OnDDGRowInit(this, ex); key = getKeyString(e.Row); if (i == 0) e.Row.Cells.FromKey(ex.column).Text = " "; if (ex.enabled) e.Row.Cells.FromKey(ex.column).Text += (UseActionBrackets ? "[" : "") + "<a href=\"BLOCKED SCRIPT" + Page.ClientScript.GetPostBackEventReference(this, ex.action + "|" + key) + "\">" + ex.link + "</a>" + (UseActionBrackets ? "]" : "") + " "; else e.Row.Cells.FromKey(ex.column).Text += (UseActionBrackets ? "[" : "") + "<span style=\"text-decoration:underline; color:gray;\">" + ex.link + "</span>" + (UseActionBrackets ? "]" : "") + " "; } } }
I figured out that some of the display layout settings needed to be set with CSS now, but a lot of the rest is still not figured out. Any ideas?
Hi aseidel,
Most of the styling is indeed done with css and most of the configuration will happen via behaviors rather than on cells or columns now. I'd suggest looking through the behaviors documentation to find what you need. Or post a more specific question so that it can be succinctly answered.
regards,
David young
Well the first thing would be the adding of an action column that was done OnInitializeLayout with UWG. How would I be able to do this with WDG?
public override void OnInitializeLayout(GridFieldCollection layout) { base.OnInitializeLayout(layout); if (ShowActionColumn && ActionFields.Count > 0 && !DisplayLayout.Bands[0].Columns.Exists("actions")) { DisplayLayout.Bands[0].Columns.Insert(0, "actions"); DisplayLayout.Bands[0].Columns.FromKey("actions").HeaderText = "Actions"; } }
I know this is an old question, but I wanted to share what I'm doing. Rather than using InitializeLayout, I'm using CustomDataBinding:
this.gridDetail.CustomDataBinding += new DataBindingEventHandler(this.gridDetail_InitializeLayout);