仅在编辑单击时将 ReadOnly 属性 设置为 devexpress 网格 (MVC) 的列
Set ReadOnly property to a column of devexpress grid(MVC) only on edit click
我的部分视图中有一个 devexpress 网格,
网格的每一行都有一个添加、更新和删除按钮。
单击特定行的更新时,会弹出一个包含网格所有列的表单。
现在我想将其中一列的只读 属性 设置为 true,这是我通过 column.ReadOnly = true;
完成的
但是这样做的目的是始终将列设置为只读,即即使在新点击期间也是如此。
因为我只想要这个只读 属性 只有在编辑点击期间。
这是我的devexpress网格代码
@{
var grid = Html.DevExpress().GridView(settings =>
{
settings.Name = "GridViewDuration";
settings.CallbackRouteValues = new { Controller = "DurationMaster", Action = "GridViewDurationPartial" };
settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "MyController", Action = "MyControllerAction1" };
settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "MyController", Action = "MyControllerAction2" };
settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "MyController", Action = "MyControllerAction3" };
settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
settings.SettingsBehavior.ConfirmDelete = true;
settings.CommandColumn.Visible = true;
settings.CommandColumn.ShowNewButton = true;
settings.CommandColumn.ShowDeleteButton = true;
settings.CommandColumn.ShowEditButton = true;
settings.KeyFieldName = "DurationId";
settings.SettingsPager.Visible = true;
settings.SettingsPager.PageSize = 20;
settings.Settings.ShowGroupPanel = true;
settings.Settings.ShowFilterRow = true;
settings.SettingsBehavior.AllowSelectByRowClick = false;
settings.Columns.Add(column =>
{
column.FieldName = "Column1";
column.ReadOnly = true;
column.Width = 20;
});
settings.Columns.Add(column =>
{
column.FieldName = "Column2";
column.Caption = "xyz";
column.ColumnType = MVCxGridViewColumnType.ComboBox;
column.Width = 250;
var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
comboBoxProperties.DataSource = PMC.Web.Controllers.DurationMasterController.getSelectList("0", "MyAction4");
comboBoxProperties.TextField = "Text";
comboBoxProperties.ValueField = "Value";
comboBoxProperties.ValueType = typeof(int);
comboBoxProperties.ValidationSettings.RequiredField.IsRequired = true;
});
settings.InitNewRow = (sender, e) =>
{
e.NewValues["ColumnId"] = 0;
};
settings.Columns.Add("ColumnName");
settings.Columns.Add("Description");
//settings.Columns.Add("DisplayName");
settings.Columns.Add(column =>
{
column.Caption = "FromDate";
column.FieldName = "FromDate";
column.ColumnType = MVCxGridViewColumnType.DateEdit;
column.ReadOnly = true;
var DateEditProperties = column.PropertiesEdit as DateEditProperties;
column.CellStyle.Wrap = DefaultBoolean.False;
});
settings.Columns.Add(column =>
{
column.Caption = "ToDate";
column.FieldName = "ToDate";
column.ColumnType = MVCxGridViewColumnType.DateEdit;
var DateEditProperties = column.PropertiesEdit as DateEditProperties;
column.CellStyle.Wrap = DefaultBoolean.False;
});
});
if (ViewData["EditError"] != null)
{
grid.SetEditErrorText((string)ViewData["EditError"]);
}
}
@grid.Bind(Model).GetHtml()
这是我的网格在初始加载时的样子。
当点击更新进行编辑时
如果我很了解你,我认为你需要使用编辑模板来解决你描述的问题。
在编辑模板操作中,您可以通过检查 属性 值 ASPxGridView.IsNewRowEditing
来检查新行是否处于编辑状态
请看下面的例子。
settings.Columns.Add(col =>
{
col.FieldName = "Id";
col.Caption = "Id";
col.SetEditItemTemplateContent(e =>
{
if (e.Grid.IsNewRowEditing)
{
// your code here
}
else
{
// your code here
}
});
});
请查看以下链接了解更多详情
MVCxGridViewColumn.SetEditItemTemplateContent
https://documentation.devexpress.com/#AspNet/DevExpressWebMvcMVCxGridViewColumn_SetEditItemTemplateContenttopic(68Z8MA)
ASPxGridView.IsNewRowEditing
https://documentation.devexpress.com/#AspNet/DevExpressWebASPxGridView_IsNewRowEditingtopic
我的部分视图中有一个 devexpress 网格,
网格的每一行都有一个添加、更新和删除按钮。
单击特定行的更新时,会弹出一个包含网格所有列的表单。
现在我想将其中一列的只读 属性 设置为 true,这是我通过 column.ReadOnly = true;
但是这样做的目的是始终将列设置为只读,即即使在新点击期间也是如此。
因为我只想要这个只读 属性 只有在编辑点击期间。
这是我的devexpress网格代码
@{
var grid = Html.DevExpress().GridView(settings =>
{
settings.Name = "GridViewDuration";
settings.CallbackRouteValues = new { Controller = "DurationMaster", Action = "GridViewDurationPartial" };
settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "MyController", Action = "MyControllerAction1" };
settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "MyController", Action = "MyControllerAction2" };
settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "MyController", Action = "MyControllerAction3" };
settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
settings.SettingsBehavior.ConfirmDelete = true;
settings.CommandColumn.Visible = true;
settings.CommandColumn.ShowNewButton = true;
settings.CommandColumn.ShowDeleteButton = true;
settings.CommandColumn.ShowEditButton = true;
settings.KeyFieldName = "DurationId";
settings.SettingsPager.Visible = true;
settings.SettingsPager.PageSize = 20;
settings.Settings.ShowGroupPanel = true;
settings.Settings.ShowFilterRow = true;
settings.SettingsBehavior.AllowSelectByRowClick = false;
settings.Columns.Add(column =>
{
column.FieldName = "Column1";
column.ReadOnly = true;
column.Width = 20;
});
settings.Columns.Add(column =>
{
column.FieldName = "Column2";
column.Caption = "xyz";
column.ColumnType = MVCxGridViewColumnType.ComboBox;
column.Width = 250;
var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
comboBoxProperties.DataSource = PMC.Web.Controllers.DurationMasterController.getSelectList("0", "MyAction4");
comboBoxProperties.TextField = "Text";
comboBoxProperties.ValueField = "Value";
comboBoxProperties.ValueType = typeof(int);
comboBoxProperties.ValidationSettings.RequiredField.IsRequired = true;
});
settings.InitNewRow = (sender, e) =>
{
e.NewValues["ColumnId"] = 0;
};
settings.Columns.Add("ColumnName");
settings.Columns.Add("Description");
//settings.Columns.Add("DisplayName");
settings.Columns.Add(column =>
{
column.Caption = "FromDate";
column.FieldName = "FromDate";
column.ColumnType = MVCxGridViewColumnType.DateEdit;
column.ReadOnly = true;
var DateEditProperties = column.PropertiesEdit as DateEditProperties;
column.CellStyle.Wrap = DefaultBoolean.False;
});
settings.Columns.Add(column =>
{
column.Caption = "ToDate";
column.FieldName = "ToDate";
column.ColumnType = MVCxGridViewColumnType.DateEdit;
var DateEditProperties = column.PropertiesEdit as DateEditProperties;
column.CellStyle.Wrap = DefaultBoolean.False;
});
});
if (ViewData["EditError"] != null)
{
grid.SetEditErrorText((string)ViewData["EditError"]);
}
}
@grid.Bind(Model).GetHtml()
这是我的网格在初始加载时的样子。
当点击更新进行编辑时
如果我很了解你,我认为你需要使用编辑模板来解决你描述的问题。
在编辑模板操作中,您可以通过检查 属性 值 ASPxGridView.IsNewRowEditing
来检查新行是否处于编辑状态请看下面的例子。
settings.Columns.Add(col =>
{
col.FieldName = "Id";
col.Caption = "Id";
col.SetEditItemTemplateContent(e =>
{
if (e.Grid.IsNewRowEditing)
{
// your code here
}
else
{
// your code here
}
});
});
请查看以下链接了解更多详情
MVCxGridViewColumn.SetEditItemTemplateContent https://documentation.devexpress.com/#AspNet/DevExpressWebMvcMVCxGridViewColumn_SetEditItemTemplateContenttopic(68Z8MA)
ASPxGridView.IsNewRowEditing https://documentation.devexpress.com/#AspNet/DevExpressWebASPxGridView_IsNewRowEditingtopic