UltraWebGrid将数据列表中的某列设置为下拉菜单样式:
1.后台添加样式:
ValueList CtlList = new ValueList(); this.gridHelper.AddDropDownlistColumn("CONTROLDATA", "管制值类型", CtlList);
AddDropDownlistColumn方法如下:
public void AddDropDownlistColumn(string key, string headerText, ValueList newValueList)
{
this.Grid.Bands[0].Columns.Add(key);
this.Grid.Bands[0].Columns.FromKey(key).HeaderText = headerText;
this.Grid.Bands[0].Columns.FromKey(key).Type = ColumnType.DropDownList;
this.Grid.Bands[0].Columns.FromKey(key).ValueList = newValueList;
this.Grid.Bands[0].Columns.FromKey(key).CellStyle.BackColor = System.Drawing.Color.White;
}
2.下拉菜单数据绑定:
定义一个ValueList,将查询出的数据Add到Valielst,最后将Valielst赋值到webgrid中"controldata"列的ValueList属性。
ValueList Valielst = this.gridWebGrid.Columns.FromKey("CONTROLDATA").ValueList; object[] objParam = sysFacade.QueryParameter("", "LF_CONTROL_TYPE", "", true, 1, 100); if (objParam != null && objParam.Length > 0) { for (int i = 0; i < objParam.Length; i++) { Valielst.ValueListItems.Add(objPara.ParameterDescription, objPara.ParameterAlias); } this.gridWebGrid.Columns.FromKey("CONTROLDATA").ValueList = Valielst; this.gridWebGrid.Columns.FromKey("CONTROLDATA").DefaultValue = this.gridWebGrid.Columns.FromKey("CONTROLDATA").ValueList.ValueListItems[0].ToString(); }
如上方式,即可实现webgrid中下拉菜单的显示。
给UltraWebGrid中下拉菜单添加切换事件(使用js实现):
1.在前台<igtbl:ultrawebgrid><DisplayLayout>......</DisplayLayout></igtbl:ultrawebgrid> 中添加代码:
<ClientSideEvents AfterCellUpdateHandler="AfterCellUpdateHandler" />
2.添加js函数
当下拉菜单切换完成时,将触发AfterCellUpdateHandler函数。
function AfterCellUpdateHandler(gridName, itemName) { var grid = igtbl_getGridById(gridName); var row = igtbl_getRowById(itemName); //获取当前行 var cell = igtbl_getCellById(itemName); //获取当前单元格 row.getCellFromKey("CONTROLDATA").Value.replace(/s+/g, ""); row.getCellFromKey("USL").setEditable(false); }
row.getCellFromKey("CONTROLDATA").Value; 获取当前行key值为CONTROLDATA的单元格的内容
row.getCellFromKey("USL").setEditable(true); setEditable用来设置单元格是否可以编辑 true:可编辑 false:不可编辑
如上,即实现了UltraWebGrid中下拉菜单的切换事件。