/// <summary> /// 添加模板列 /// </summary> /// <param name="key"></param> /// <param name="text"></param> /// <param name="style"></param> /// <param name="width"></param> /// <param name="align"></param> /// <param name="hidden"></param> private void AddTemplateColumn(string key, string text, NewColumnStyle style, int width, HorizontalAlign align, bool hidden) { if (!this.dtSource.Columns.Contains(key)) { this.dtSource.Columns.Add(key); this.dtSource.AcceptChanges(); } TemplateDataField tempCol = this.Grid.Columns.FromKey(key) as TemplateDataField; if (tempCol == null) { tempCol = new TemplateDataField(); tempCol.Key = key; this.Grid.Columns.Add(tempCol); } tempCol.ItemTemplate = new CustomColumnTemplate(key, text, style, DataControlRowType.DataRow, align); tempCol.HeaderTemplate = new CustomColumnTemplate(key, text, style, DataControlRowType.Header, align); if (width != 0) { tempCol.Width = new System.Web.UI.WebControls.Unit(width); } tempCol.Hidden = hidden; //模板列不需要排序 SortingColumnSetting sortColSet = new SortingColumnSetting(this.Grid); sortColSet.ColumnKey = key; sortColSet.Sortable = false; this.Grid.Behaviors.CreateBehavior <Sorting>().ColumnSettings.Add(sortColSet); }
//public Control ChildControl; public CustomColumnTemplate(string controlId, string colname, NewColumnStyle style, DataControlRowType type, HorizontalAlign align) { this.columnName = colname; this.cId = controlId; this.templateType = type; this.colStyle = style; this.align = align; }
private void AddTemplateColumn(string key, string text, NewColumnStyle style) { AddTemplateColumn(key, text, style, 0, HorizontalAlign.Left, false); }
private void AddTemplateColumn(string key, string text, NewColumnStyle style, HorizontalAlign align, bool hidden) { AddTemplateColumn(key, text, style, 0, align, hidden); }