/// <summary> /// 新增特殊的勾选框列,head为勾选框 /// </summary> /// <param name="key"></param> public void AddGreatCheckBoxColumn(string key) { 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(); col.Key = key; col.HeaderChecked = true; col.Width = new System.Web.UI.WebControls.Unit(30); //设置水平位置 col.CssClass = HorizontalAlign.Center.ToString(); col.Header.CssClass = HorizontalAlign.Center.ToString(); //col.HeaderCheckBoxMode = CheckBoxMode.TriState; 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); }
// 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); }