在编辑期间设置 Telerik MVC 网格列属性 [英] Setting Telerik MVC grid column properties during an Edit

查看:33
本文介绍了在编辑期间设置 Telerik MVC 网格列属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 MVC 3 Razor Telerik 网格.我在该行有一个编辑命令.

I have an MVC 3 Razor Telerik grid. I have an Edit comand on the row.

当用户单击编辑"(这会将网格置于带有更新"和取消"按钮的编辑"模式)时,我想将其中两列的属性设置为只读.

When a user clicks on Edit (this places the grid in Edit mode with an Update and Cancel button), I want to set a property for two of the columns to readonly.

当用户点击取消或更新时,我想将列设置回完全权限.

When the user clicks on Cancel or Update, I want to set the columns back to full permission.

我知道控制器中必须有一些属性,当为此按下编辑"按钮时我应该能够设置,但还没有看到任何有关如何完成此操作的文档.

I know there must be some properties in the controller I should be able to set when the Edit button is pressed for this, but have not seen any docs on how to accomplish this.

我该怎么做?

我使用的是 2011.2.712.340 版的控件.

I'm using version 2011.2.712.340 of the controls.

推荐答案

你上面的描述听起来有点令人困惑.readonly 属性的目的是确保当您的行进入编辑模式时,无法编辑显式设置为 readonly 的列,这似乎是您要查找的内容.在常规读取模式下,无论是否设置了 readonly,所有列都将具有相同的权限,因为您只是查看数据而不是编辑.

What your describing above sounds a little bit confusing. The purpose of the readonly property is to ensure that when your row enters edit mode the columns that had readonly explicitly set cannot be edited, which seems to be what you're looking for. When in regular read mode all columns will have the same permission whether or not readonly was set, since you are just viewing the data and not editing.

在评论澄清后

似乎您希望在插入记录时可以编辑此字段,而不是在编辑行时.嗯,这可以使用一些 JavaScript 来完成.如果您使用 Ajax 绑定(触发此事件的唯一方法),您可以通过订阅 onEdit 客户端事件来执行以下操作:

Seems like you want to have this field editable when you are inserting a record, but not when you edit the row. Well, this can be done using some JavaScript. If you use Ajax binding (the only way to fire this event) you can do the following by subscribing to the onEdit client-side event:

...
.ClientEvents(clientEvents => clientEvents.OnEdit("onEdit"))
...

这是 JavaScript:

And here's the JavaScript:

<script type="text/javascript">
function onEdit(e) {
    var form = e.form;
    var mode = e.mode;

    if (mode == "edit") {
        var country = form.Country; //Country is a public property of my Model
        country.disabled = true;
    }
}

正如您在上面看到的,我获得了带有关联编辑行的表单,并专门抓取了与我不想编辑的属性关联的字段并禁用该输入元素.

As you can see above, I get the form with the associated edited row and specifically grab the field associated with the property I do not want to be edited and disable that input element.

这篇关于在编辑期间设置 Telerik MVC 网格列属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆