[关闭]
@Aiti 2017-05-17T05:46:27.000000Z 字数 4732 阅读 391

DevExpress事件

未分类


RowInserting/* 新增记录时,给实体类中字段列赋值保存到数据库;*/

  1. protected void gvAll_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
  2. {
  3. //e.NewValues["Author"] = currentUser;
  4. e.NewValues["CreateTime"] = DateTime.Now;
  5. }

CellEditorInitialize/* 新增记录;枚举类下拉框选择显示*/切换到编辑模式,使您可以初始化细胞编辑

  1. protected void gvAll_CellEditorInitialize(object sender, DevExpress.Web.ASPxTreeList.TreeListColumnEditorEventArgs e)
  2. {
  3. if (e.Column.FieldName == "Type")
  4. {
  5. ASPxComboBox combo = e.Editor as ASPxComboBox;
  6. EnumHelper.SetListControl(combo, typeof(Module.Component.CatalogType));
  7. }
  8. else if (e.Column.FieldName == "LoginName")
  9. if (gvUsers.IsNewRowEditing)
  10. e.Editor.ReadOnly = false;
  11. else
  12. e.Editor.ReadOnly = true;
  13. }

CustomColumnDisplayText/* 显示记录时;枚举类显示汉字;改变变量显示的格式;样式*/可以用来为任何细胞的自定义显示的文本

  1. protected void ASPxGridView1_CustomColumnDisplayText(object sender, ASPxGridViewColumnDisplayTextEventArgs e)
  2. {
  3. if (e.Column.FieldName == "type")
  4. {
  5. e.DisplayText = cellValue.Substring(e.value) ;
  6. }
  7. if (e.Column.FieldName == "Content")
  8. {
  9. if (e.Value != null)
  10. {
  11. string cellValue = e.Value.ToString();
  12. if (cellValue.Length > 60)
  13. e.DisplayText = cellValue.Substring(0, 60) + "...";
  14. }
  15. }
  16. }

OnCustomGroupDisplayText/* 显示记录时;改变Group变量显示的格式;样式*/

  1. <dx:GridViewDataTextColumn FieldName="Type" VisibleIndex="0" Caption="审批类型" GroupIndex="1">
  2. </dx:GridViewDataTextColumn>
  3. protected void gv_CustomGroupDisplayText(object sender, DevExpress.Web.ASPxGridViewColumnDisplayTextEventArgs e)
  4. {
  5. switch (e.Value.ToString())
  6. {
  7. case "Person":
  8. e.DisplayText = "人员信息";
  9. break;
  10. case "PersonTest":
  11. e.DisplayText = "试验人员信息";
  12. break;
  13. }
  14. }

CommandButtonInitialize/* 增删该查按钮*/

  1. protected void ASPxGridView1_CommandButtonInitialize(object sender, ASPxGridViewCommandButtonEventArgs e)
  2. {
  3. if (e.ButtonType == ColumnCommandButtonType.New || e.ButtonType == ColumnCommandButtonType.Delete)
  4. {
  5. if (User.IsInRole("Admin"))
  6. e.Visible = true;
  7. else
  8. e.Visible = false;
  9. }
  10. if (e.ButtonType == ColumnCommandButtonType.Edit)
  11. {
  12. var obj = gvAll.GetRow(e.VisibleIndex) as ProjectApprovalModel;
  13. //var obj = (Article)gvAll.GetRow(e.VisibleIndex) ;
  14. e.Visible = currentUser == obj.Author && obj.CanEdit;
  15. }
  16. }

CustomCallback/* 提交按钮*/

  1. function gv_OnCustomButtonClick(s, e) {
  2. if (e.buttonID == "btnView") {
  3. window.open('ArticleView.aspx?id=' + s.GetRowKey(e.visibleIndex));
  4. } else if (e.buttonID == "btnSubmit") {
  5. if (confirm("确认提交通过此条信息?")) {
  6. s.PerformCallback(s.GetRowKey(e.visibleIndex));
  7. }
  8. }
  9. }
  1. <dx:ASPxGridView ID="gvAll" runat="server" AutoGenerateColumns="False" DataSourceID="XpoDs" KeyFieldName="Oid" OnCustomCallback="gvAll_CustomCallback" >
  2. <ClientSideEvents CustomButtonClick="function(s,e){gv_OnCustomButtonClick(s, e)}" />
  3. <Columns>
  4. <dx:GridViewCommandColumn ShowNewButtonInHeader="true" ShowEditButton="true" ShowDeleteButton="true" VisibleIndex="0">
  5. <CustomButtons>
  6. <dx:GridViewCommandColumnCustomButton ID="btnView" Text="详情"></dx:GridViewCommandColumnCustomButton>
  7. <dx:GridViewCommandColumnCustomButton ID="btnSubmit" Text="提交"></dx:GridViewCommandColumnCustomButton>
  8. </CustomButtons>
  9. </dx:GridViewCommandColumn>

后台代码

  1. protected void gvAll_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
  2. {
  3. var obj = session.FindObject<Article>(CriteriaOperator.Parse("Oid=?", e.Parameters));
  4. obj.IsAuditing = true;
  5. obj.Save();
  6. gvAll.DataBind();
  7. }

HtmlDataCellPrepared/数据单元内的套件中当对应表/枚举类变多选框/

htmldatacellprepared事件引发的每个数据单元内的套件中当对应表细胞已创建。您可以处理此事件以更改单个单元格的样式设置。

  1. protected void gvAll_HtmlDataCellPrepared(object sender, ASPxGridViewTableDataCellEventArgs e)
  2. {
  3. if ((gvAll.EditingRowVisibleIndex == e.VisibleIndex && e.DataColumn.FieldName == "PropertieNames") && !gvAll.IsNewRowEditing)
  4. {
  5. var cbl = gvAll.FindEditRowCellTemplateControl(gvAll.DataColumns["Properties"], "chxProperties") as ASPxCheckBoxList;
  6. var o = gvAll.GetRow(e.VisibleIndex) as Article;
  7. var values = o?.Properties?.Split(',');
  8. if (values != null && values[0].Length>0)
  9. {
  10. foreach (ListEditItem item in cbl.Items)
  11. {
  12. if (values.Contains(item.Value))
  13. item.Selected = true;
  14. }
  15. }
  16. }
  17. }

HtmlRowCreated/*列创建时/列序号

分组时 - 添加列序号

  1. int _rowIndex;
  2. protected void gvAll_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e)
  3. {
  4. //序号
  5. if (e.RowType == GridViewRowType.Group)
  6. {
  7. _rowIndex = 0;
  8. }
  9. else if (e.RowType == GridViewRowType.Data)
  10. {
  11. _rowIndex++;
  12. if (!gvAll.IsEditing) // 编辑时,首行会回调错误
  13. ((ProjectContractModel)gvAll.GetRow(e.VisibleIndex)).Num = _rowIndex;
  14. e.Row.Cells[3].Text = _rowIndex.ToString();
  15. }
  16. }

不分组时-添加列序号

  1. protected void gvAll_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e)
  2. {
  3. //序号
  4. if (e.RowType == GridViewRowType.Data)
  5. e.Row.Cells[1].Text = e.VisibleIndex.ToString();
  6. }

HtmlRowPrepared /*html页面数据行的样式(颜色)

  1. protected void gvAll_HtmlRowPrepared(object sender, ASPxGridViewTableRowEventArgs e)
  2. {
  3. if(!gvAll.IsEditing && gvAll.EditingRowVisibleIndex<0 && e.VisibleIndex>= 0 && e.RowType == GridViewRowType.Data)
  4. {
  5. var InspectDate = gvAll.GetRowValues(e.VisibleIndex, "InspectDate");
  6. var eq = gvAll.GetRow(e.VisibleIndex) as EquipmentTest;
  7. if (InspectDate != null && ((DateTime)InspectDate).Subtract(DateTime.Now).TotalDays < 30 && eq.IsFirstComplete && eq.EquipmentStatus == EquipmentStatus.Normal)
  8. e.Row.BackColor = System.Drawing.Color.Red;
  9. }
  10. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注