/// <summary> /// 新增普通的数据绑定列,默认水平居左,如需设定水平位置,请使用模板列 /// </summary> /// <param name="key"></param> /// <param name="headerText"></param> /// <param name="width"></param> /// <param name="hidden"></param> /// <param name="readOnly">是否只读(解决列是否可以编辑) add by jinger 20160308</param> /// <param name="align"></param> public void AddDataColumn(string key, string headerText, int width, bool hidden, bool readOnly, HorizontalAlign align) { if (!this.dtSource.Columns.Contains(key)) { this.dtSource.Columns.Add(key); this.dtSource.AcceptChanges(); } if (this.Grid.Columns.FromKey(key) != null) { return; } BoundDataField col = new BoundDataField(); col.Key = key; col.Header.Text = headerText; col.CssClass = align.ToString(); col.Header.CssClass = align.ToString(); if (width != 0) { col.Width = new System.Web.UI.WebControls.Unit(width); } this.Grid.Columns.Add(col); col.Hidden = hidden; EditingColumnSetting checkCol = new EditingColumnSetting(this.Grid); checkCol.ColumnKey = key; checkCol.ReadOnly = readOnly; this.Grid.Behaviors.CreateBehavior <EditingCore>().Behaviors.CreateBehavior <CellEditing>().ColumnSettings.Add(checkCol); }
public void AddEditColumn(string key, string text) { if (!this.dtSource.Columns.Contains(key)) { this.dtSource.Columns.Add(key); this.dtSource.AcceptChanges(); } if (this.Grid.Columns.FromKey(key) != null) { return; } BoundDataField col = new BoundDataField(); col.Key = key; col.Header.Text = text; col.CssClass = "tdEdit"; col.Header.CssClass = HorizontalAlign.Center.ToString(); col.Width = new System.Web.UI.WebControls.Unit(70); //不可以改变列宽 ColumnResizeSetting crs = new ColumnResizeSetting(this.Grid); crs.EnableResize = false; crs.ColumnKey = key; this.Grid.Behaviors.CreateBehavior <ColumnResizing>().ColumnSettings.Add(crs); //不可以排序 SortingColumnSetting sortColSet = new SortingColumnSetting(this.Grid); sortColSet.ColumnKey = key; sortColSet.Sortable = false; this.Grid.Behaviors.CreateBehavior <Sorting>().ColumnSettings.Add(sortColSet); EditingColumnSetting checkCol = new EditingColumnSetting(this.Grid); checkCol.ColumnKey = key; checkCol.ReadOnly = true; this.Grid.Behaviors.CreateBehavior <EditingCore>().Behaviors.CreateBehavior <CellEditing>().ColumnSettings.Add(checkCol); this.Grid.Columns.Add(col); //原来的方式-使用模板列 //模板列的方式会降低速度,所以不采用 //AddTemplateColumn(key, text, NewColumnStyle.Edit, HorizontalAlign.Center); }
// header 有checkbox public void AddCheckBoxColumn1(string key, string text, bool isreadonly, int width) { if (!this.dtSource.Columns.Contains(key)) { this.dtSource.Columns.Add(key, typeof(bool)); this.dtSource.AcceptChanges(); } if (this.Grid.Columns.FromKey(key) != null) { return; } UnboundCheckBoxField col = new UnboundCheckBoxField(); //BoundCheckBoxField col = new BoundCheckBoxField(); col.Key = key; if (width > 0) { col.Width = new System.Web.UI.WebControls.Unit(width); } else { col.Width = new System.Web.UI.WebControls.Unit(30); } col.Header.Text = text; col.HeaderChecked = false; //设置水平位置 col.CssClass = HorizontalAlign.Center.ToString(); col.Header.CssClass = HorizontalAlign.Center.ToString(); this.Grid.Columns.Add(col); //checkbox列不需要排序 SortingColumnSetting sortColSet = new SortingColumnSetting(this.Grid); sortColSet.ColumnKey = key; sortColSet.Sortable = false; this.Grid.Behaviors.CreateBehavior <Sorting>().ColumnSettings.Add(sortColSet); EditingColumnSetting checkCol = new EditingColumnSetting(this.Grid); checkCol.ColumnKey = key; checkCol.ReadOnly = isreadonly; this.Grid.Behaviors.CreateBehavior <EditingCore>().Behaviors.CreateBehavior <CellEditing>().ColumnSettings.Add(checkCol); }