protected override void InitWebGrid() { base.InitWebGrid(); this.gridHelper.AddColumn("ColumnSequence", "次序", null); this.gridHelper.AddColumn("ColumnName", "栏位名称", null); this.gridHelper.AddColumn("Description", "栏位描述", null); this.gridHelper.AddDataColumn("DataType", "数据类型", 150); this.gridHelper.AddCheckBoxColumn("Visible", "是否可见", true, 100); this.gridWebGrid.Behaviors.CreateBehavior <EditingCore>().Behaviors.CreateBehavior <CellEditing>().ColumnSettings["Description"].ReadOnly = false; //cell有下拉框 DropDownProvider dropdownProvider = new DropDownProvider(); dropdownProvider.ID = "dropdownProviderDataType"; dropdownProvider.EditorControl.ID = "editorControlDataType"; dropdownProvider.EditorControl.DisplayMode = DropDownDisplayMode.DropDownList; dropdownProvider.EditorControl.TextField = "DataTypeText"; dropdownProvider.EditorControl.ValueField = "DataTypeValue"; dropdownProvider.EditorControl.DropDownContainerWidth = new Unit(150); BindDropDownDataType(dropdownProvider); this.gridWebGrid.EditorProviders.Add(dropdownProvider); this.gridWebGrid.Behaviors.CreateBehavior <EditingCore>().Behaviors.CreateBehavior <CellEditing>().ColumnSettings["DataType"].ReadOnly = false; this.gridWebGrid.Behaviors.CreateBehavior <EditingCore>().Behaviors.CreateBehavior <CellEditing>().ColumnSettings["DataType"].EditorID = "dropdownProviderDataType"; //下拉框列固定列宽 ColumnResizeSetting crs = new ColumnResizeSetting(this.gridWebGrid); crs.EnableResize = false; crs.ColumnKey = "DataType"; this.gridWebGrid.Behaviors.CreateBehavior <ColumnResizing>().ColumnSettings.Add(crs); //是否可见列可编辑 this.gridWebGrid.Behaviors.CreateBehavior <EditingCore>().Behaviors.CreateBehavior <CellEditing>().ColumnSettings["Visible"].ReadOnly = false; //InitRow(); //多语言 this.gridHelper.ApplyLanguage(this.languageComponent1); this.cmdQuery_Click(null, null); }
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); }