@Aiti
2017-05-17T05:46:27.000000Z
字数 4732
阅读 453
未分类
protected void gvAll_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e){//e.NewValues["Author"] = currentUser;e.NewValues["CreateTime"] = DateTime.Now;}
protected void gvAll_CellEditorInitialize(object sender, DevExpress.Web.ASPxTreeList.TreeListColumnEditorEventArgs e){if (e.Column.FieldName == "Type"){ASPxComboBox combo = e.Editor as ASPxComboBox;EnumHelper.SetListControl(combo, typeof(Module.Component.CatalogType));}else if (e.Column.FieldName == "LoginName")if (gvUsers.IsNewRowEditing)e.Editor.ReadOnly = false;elsee.Editor.ReadOnly = true;}
protected void ASPxGridView1_CustomColumnDisplayText(object sender, ASPxGridViewColumnDisplayTextEventArgs e){if (e.Column.FieldName == "type"){e.DisplayText = cellValue.Substring(e.value) ;}if (e.Column.FieldName == "Content"){if (e.Value != null){string cellValue = e.Value.ToString();if (cellValue.Length > 60)e.DisplayText = cellValue.Substring(0, 60) + "...";}}}
<dx:GridViewDataTextColumn FieldName="Type" VisibleIndex="0" Caption="审批类型" GroupIndex="1"></dx:GridViewDataTextColumn>protected void gv_CustomGroupDisplayText(object sender, DevExpress.Web.ASPxGridViewColumnDisplayTextEventArgs e){switch (e.Value.ToString()){case "Person":e.DisplayText = "人员信息";break;case "PersonTest":e.DisplayText = "试验人员信息";break;}}
protected void ASPxGridView1_CommandButtonInitialize(object sender, ASPxGridViewCommandButtonEventArgs e){if (e.ButtonType == ColumnCommandButtonType.New || e.ButtonType == ColumnCommandButtonType.Delete){if (User.IsInRole("Admin"))e.Visible = true;elsee.Visible = false;}if (e.ButtonType == ColumnCommandButtonType.Edit){var obj = gvAll.GetRow(e.VisibleIndex) as ProjectApprovalModel;//var obj = (Article)gvAll.GetRow(e.VisibleIndex) ;e.Visible = currentUser == obj.Author && obj.CanEdit;}}
function gv_OnCustomButtonClick(s, e) {if (e.buttonID == "btnView") {window.open('ArticleView.aspx?id=' + s.GetRowKey(e.visibleIndex));} else if (e.buttonID == "btnSubmit") {if (confirm("确认提交通过此条信息?")) {s.PerformCallback(s.GetRowKey(e.visibleIndex));}}}
<dx:ASPxGridView ID="gvAll" runat="server" AutoGenerateColumns="False" DataSourceID="XpoDs" KeyFieldName="Oid" OnCustomCallback="gvAll_CustomCallback" ><ClientSideEvents CustomButtonClick="function(s,e){gv_OnCustomButtonClick(s, e)}" /><Columns><dx:GridViewCommandColumn ShowNewButtonInHeader="true" ShowEditButton="true" ShowDeleteButton="true" VisibleIndex="0"><CustomButtons><dx:GridViewCommandColumnCustomButton ID="btnView" Text="详情"></dx:GridViewCommandColumnCustomButton><dx:GridViewCommandColumnCustomButton ID="btnSubmit" Text="提交"></dx:GridViewCommandColumnCustomButton></CustomButtons></dx:GridViewCommandColumn>
后台代码
protected void gvAll_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e){var obj = session.FindObject<Article>(CriteriaOperator.Parse("Oid=?", e.Parameters));obj.IsAuditing = true;obj.Save();gvAll.DataBind();}
htmldatacellprepared事件引发的每个数据单元内的套件中当对应表细胞已创建。您可以处理此事件以更改单个单元格的样式设置。
protected void gvAll_HtmlDataCellPrepared(object sender, ASPxGridViewTableDataCellEventArgs e){if ((gvAll.EditingRowVisibleIndex == e.VisibleIndex && e.DataColumn.FieldName == "PropertieNames") && !gvAll.IsNewRowEditing){var cbl = gvAll.FindEditRowCellTemplateControl(gvAll.DataColumns["Properties"], "chxProperties") as ASPxCheckBoxList;var o = gvAll.GetRow(e.VisibleIndex) as Article;var values = o?.Properties?.Split(',');if (values != null && values[0].Length>0){foreach (ListEditItem item in cbl.Items){if (values.Contains(item.Value))item.Selected = true;}}}}
分组时 - 添加列序号
int _rowIndex;protected void gvAll_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e){//序号if (e.RowType == GridViewRowType.Group){_rowIndex = 0;}else if (e.RowType == GridViewRowType.Data){_rowIndex++;if (!gvAll.IsEditing) // 编辑时,首行会回调错误((ProjectContractModel)gvAll.GetRow(e.VisibleIndex)).Num = _rowIndex;e.Row.Cells[3].Text = _rowIndex.ToString();}}
不分组时-添加列序号
protected void gvAll_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e){//序号if (e.RowType == GridViewRowType.Data)e.Row.Cells[1].Text = e.VisibleIndex.ToString();}
protected void gvAll_HtmlRowPrepared(object sender, ASPxGridViewTableRowEventArgs e){if(!gvAll.IsEditing && gvAll.EditingRowVisibleIndex<0 && e.VisibleIndex>= 0 && e.RowType == GridViewRowType.Data){var InspectDate = gvAll.GetRowValues(e.VisibleIndex, "InspectDate");var eq = gvAll.GetRow(e.VisibleIndex) as EquipmentTest;if (InspectDate != null && ((DateTime)InspectDate).Subtract(DateTime.Now).TotalDays < 30 && eq.IsFirstComplete && eq.EquipmentStatus == EquipmentStatus.Normal)e.Row.BackColor = System.Drawing.Color.Red;}}