設置只讀屬性的DevExpress網格(MVC)的專欄中,我有一個網格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()
我試過了,才發現整個Datecontrol的列disaap耳朵,而不是隻使其只讀@peters –
它消失了,因爲這只是一個例子。您需要在'if'語句中添加特定的Devexpress MVC控件定義。這會將HTML控制輸出寫入ViewContext.Writer。是這樣的: '代碼 ViewContext.Writer.Write( Html.DevExpress()DateEdit(settingsDateEdit => { settingsDateEdit.Name = 「FROM日期」; settingsDateEdit.Width = Unit.Percentage(100)。 ; settingsDateEdit.ReadOnly =!e.Grid.IsNewRowEditing; })。Bind(fromDate).GetHtml() ); ' – PeterS
請試試這個,讓我知道它是否適合你。如果有什麼不清楚的,請讓我知道:) – PeterS