Setting Telerik MVC grid column properties during an Edit

旧城冷巷雨未停 提交于 2019-12-08 10:20:00

问题


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.

How can I do this?

I'm using version 2011.2.712.340 of the controls.


回答1:


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.

Edit after clarification from comment:

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"))
...

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.



来源:https://stackoverflow.com/questions/7823680/setting-telerik-mvc-grid-column-properties-during-an-edit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!