protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ClientGrid cg = new ClientGrid() { ID = "ClientGrid1", OnCellCreatedEditor = "OnCellCreatedEditor", Width = Unit.Point(820) }; cg.Columns.Add(new ClientGridColumn() { ItemStyle = "{width:'20px'}", SelectColumn = true, ShowSelectAll = true, }); cg.Columns.Add(new ClientGridColumn() { ItemStyle = "{width:'300px'}", HeaderText = "员工编码", DataField = "SelectedUserId", DataType = DataType.String, }); cg.Columns.Add(new ClientGridColumn() { ItemStyle = "{width:'200px'}", HeaderText = "员工姓名", DataField = "SelectedUserDisplayName", DataType = DataType.String }); cg.Columns.Add(new ClientGridColumn() { ItemStyle = "{width:'300px'}", HeaderText = "人员标示", DataField = "SelectedUserUserFullPath", DataType = DataType.String }); div_container.Controls.Add(cg); List<myDemoUser> list = new List<myDemoUser>(); cg.InitialData = list; } }
private void SettleControlColumnsFromXmlNode(Control currentControl, XmlNode rootNode) { foreach (XmlNode node in rootNode.ChildNodes) { ClientGridColumn column = new ClientGridColumn(); foreach (XmlAttribute attr in node.Attributes) { PropertyInfo piDest = TypePropertiesCacheQueue.Instance.GetPropertyInfo(column.GetType(), attr.Name); if (piDest != null) { if (attr.Value.IsNullOrEmpty() || piDest.CanWrite == false) { continue; } if (piDest.PropertyType == typeof(Unit)) { piDest.SetValue(column, Unit.Parse(attr.Value), null); } else if (piDest.PropertyType == typeof(bool)) { piDest.SetValue(column, bool.Parse(attr.Value), null); } else { piDest.SetValue(column, attr.Value, null); } } } var subNode = node.SelectSingleNode("editTemplate"); if (subNode != null) { column.EditTemplate = new ClientGridColumnEditTemplate(); foreach (XmlAttribute subAttr in subNode.Attributes) { PropertyInfo piDest = TypePropertiesCacheQueue.Instance.GetPropertyInfo(column.EditTemplate.GetType(), subAttr.Name); if (piDest != null) { if (subAttr.Value.IsNullOrEmpty() || piDest.CanWrite == false) { continue; } if (piDest.PropertyType.IsEnum) { var enumValue = DataConverter.ChangeType(subAttr.Value, piDest.PropertyType); piDest.SetValue(column.EditTemplate, enumValue, null); } else if (piDest.PropertyType == typeof(Unit)) { piDest.SetValue(column.EditTemplate, Unit.Parse(subAttr.Value), null); } else if (piDest.PropertyType == typeof(bool)) { piDest.SetValue(column.EditTemplate, bool.Parse(subAttr.Value), null); } else { piDest.SetValue(column.EditTemplate, subAttr.Value, null); } } } } ClientGrid gridControl = (ClientGrid)currentControl; gridControl.Columns.Add(column); } }