Disable editing a column (inline edit)

I'm using the DataGrid inline Edit.
But I need to lock some columns in editing. How can I disable editing of a specific column?, I didn't find any property.

You can either define EditTemplate with logic than will display editor or just value or you can remove EditTemplate if you do not want editing for specific column.

Hi,
I'm trying to disable editing a column in code. I guessed that removing EditTemplate would by the way, as @enchev suggested. I have defined EditTemplate in razor and I'm trying to remove it by column.EditTemplate = null in OnAfterRender, but editor is still displayed. Any suggestion?

Setting the template to null will not work. Try using @if with a condition inside the edit template.

1 Like

Hi,
You can either remove the editing control itself for required fields from razor file


Other wise set enabled property false for those controls

Both suggestions are working, thank you!
I thought initially using @if should work, but I put it outside EditTample tag and it is erroneous there, and I didn't pay much attention to this since I decided to use a method in code, where I'm already iterating grid's columns to set their visibility based on some conditions.
I still think of removing EditTemplates in razor and try adding a template in code (that same loop) for each column that should be editable (again based on some conditions) but I'm not sure is that possible and how to add the EditTemplate in the code?

Refer this
Link on codeproject. I could add dynamic controls for one of my pages based on this.