如何为某些字段设置隐藏的DevExpress MVC GridView Edit按钮?

时间:2014-08-07 11:46:32

标签: asp.net-mvc-4 devexpress

我的项目中有一个DevExpress MVC GridView,我想在某些字段中隐藏DevExpress MVC GridView Edit按钮。任何想法?

这是我的观看代码。

@Html.DevExpress().GridView(settings =>
{
    settings.Name = "GridView";
    settings.CallbackRouteValues = new { Controller = "Home", Action =   "GridViewPartial" };

    settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Home", Action = "GridViewPartialAddNew" };
    settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Home", Action = "GridViewPartialUpdate" };
    settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Home", Action = "GridViewPartialDelete" };
    settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
    settings.SettingsBehavior.ConfirmDelete = true;

    settings.CommandColumn.Visible = true;
    settings.CommandColumn.NewButton.Visible = true;
    settings.CommandColumn.DeleteButton.Visible = true;
    settings.CommandColumn.EditButton.Visible = true;

    settings.KeyFieldName = "FirstCmOutputId";

    settings.SettingsPager.Visible = true;
    settings.Settings.ShowGroupPanel = true;
    settings.Settings.ShowFilterRow = true;
    settings.SettingsBehavior.AllowSelectByRowClick = true;


    settings.SettingsDetail.AllowOnlyOneMasterRowExpanded = true;
    settings.SettingsDetail.ShowDetailRow = true;

    settings.Columns.Add("Name");
    settings.Columns.Add("Intervention");
    settings.Columns.Add("Indicator");
    settings.Columns.Add("UseOfOutput");
    settings.Columns.Add("UserOfOutput");
    settings.Columns.Add("PlanningFrom");
    settings.Columns.Add("PlanningTo");
    settings.Columns.Add("DateOfPlanning");
    settings.Columns.Add("City");

    settings.SetDetailRowTemplateContent(c => {
            Html.RenderAction("GridView1Partial", new { OutputID =  DataBinder.Eval(c.DataItem, "FirstCmOutputId") });
        });
}).Bind(Model).GetHtml()

在上面的视图代码中,所有字段都启用了“编辑”按钮,但我需要为某些字段禁用“编辑”按钮。任何帮助将不胜感激。

此致

2 个答案:

答案 0 :(得分:0)

这适用于将来会搜索相同内容的人。 您可以轻松控制给定行的命令按钮的状态

settings.CommandButtonInitialize = (sender, e) =>
    {
        if (e.VisibleIndex == -1) return;
        if (e.ButtonType == ColumnCommandButtonType.Edit)
        {
            e.Column.Visible = (bool)((MVCxGridView)sender).GetRowValues(e.VisibleIndex, "MyBoolProperty");
        }
    };

答案 1 :(得分:0)

只需更新最新的Devexpress 采用 e.visible而不是e.Column.Visible