public virtual void ToUControl(UControl container, WC.GridViewCommandEventHandler handler, WC.GridViewPageEventHandler pagingHandler, WC.GridViewSortEventHandler sortingHandler, string navigateUrl = null) { // take care of all the dependant controls as well WC.GridView grid = new WC.GridView(); string[] DataKeyNames = PKColNames.ToArray(); if (CE.GlobalState == GlobalState.Administer) { // one of our datakeys may have been a FK and its value is now the representative field of the // foreign table, not our key, but in such cases the key will be stored in a prefixed column. for (int i = 0; i < DataKeyNames.Length; i++) { FK fk = FKs.Where(x => x.myColumn == DataKeyNames[i]).FirstOrDefault(); if (fk is FK) { DataKeyNames[i] = CC.TABLE_COLUMN_REAL_VALUE_PREFIX + DataKeyNames[i]; } } } grid.DataKeyNames = DataKeyNames; grid.AutoGenerateColumns = false; WC.TemplateField tf = new WC.TemplateField(); tf.HeaderTemplate = new SummaryGridCommandColumn(WC.ListItemType.Header); tf.FooterTemplate = new SummaryGridCommandColumn(WC.ListItemType.Footer); tf.ItemTemplate = new SummaryGridCommandColumn(WC.ListItemType.Item, actions); grid.Columns.Add(tf); foreach (string col in displayColumns) { WC.BoundField bf = new WC.BoundField(); bf.DataField = col; bf.HeaderText = col + " [-]"; bf.SortExpression = col; grid.Columns.Add(bf); } // must contain the whole PK even if it is not displayed - for the navigator // DataKeyNames are the real ones - including "_" prefixing foreach (string col in DataKeyNames) { if (displayColumns.Contains(col)) { continue; } WC.BoundField bf = new WC.BoundField(); bf.DataField = col; bf.Visible = false; grid.Columns.Add(bf); bf.HeaderText = col; } grid.AllowSorting = true; //PBPR container.Controls.Add(grid); grid.PagerStyle.CssClass = "navTablePaging"; grid.CssClass = "navTable"; grid.AllowPaging = true; grid.PageSize = 25; grid.PageIndexChanging += pagingHandler; grid.Sorting += sortingHandler; grid.DataSource = data.DefaultView; grid.DataBind(); //PBPR grid.RowCommand += handler; grid.ID = "Control" + controlId; }