Setting Telerik MVC grid column properties during

2019-06-10 22:51发布

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条回答
Animai°情兽
2楼-- · 2019-06-10 23:12

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.

查看更多
登录 后发表回答