This is a migrated thread and some comments may be shown as answers.

[Solved] ReadOnlyAttribute and GridEditMode.InForm

4 Answers 155 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
JULIA
Top achievements
Rank 1
JULIA asked on 17 Aug 2010, 06:55 PM
Hello,

the ReadOnlyAttribute work for GridEditMode.InLine but not for GridEditMode.InForm. Also the GridColumnBuilder.ReadOnly Method works only for InLine Mode.
Is there any solution for this?

Regards,
Timo

4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 18 Aug 2010, 07:10 AM
Hi Timo,

 This is by design. 

In in-line mode Telerik Grid for ASP.NET MVC is creating an editor for each column. As a result only the properties which are displayed as columns are editable. The ReadOnly attribute is applicable there.

In in-forms or pop-up mode Telerik Grid for ASP.NET MVC is creating an editor for the bound object (using Html.EditorFor<T>). As a result all editable properties of the bound object are displayed in the edit form. This behavior differs from in-line mode where only the bound properties (properties for which a column is defined) are editable. To hide properties from the grid edit form use the ScaffoldColumnAttribute:

public class Product { [ScaffoldColumn(false)] public int ProductID { get; set; } }

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
JULIA
Top achievements
Rank 1
answered on 18 Aug 2010, 07:28 AM
Hi,

i dont want hide a column. i want display a readonly column for a specific property?
how can i achieve this goal?

Regards,
Timo
0
Jigar
Top achievements
Rank 1
answered on 18 Aug 2010, 07:41 AM
Hi timo,

I had the same requirement; i had LastModifiedDateTime column in my table, which i want readonly..

Model:

    
<DisplayName("ModifiedDateTime")>
<DisplayFormat(ApplyFormatInEditMode:=
True, HtmlEncode:=True)>
<UIHint(
"ModifiedDateTime")>
Public Property modifieddatetime As DateTime


Component:   
<%@ Control Language="VB" Inherits="System.Web.Mvc.ViewUserControl(Of System.DateTime?)" %><br>     <%= Html.TextBox("", Now(), New Dictionary(Of String, Object) From {{"readonly", "readonly"}})%> 

After this it always shows current date time in readonly mode in both display and edit mode. You may modified it as per your requirement.

this may help ..

Regards.
0
Atanas Korchev
Telerik team
answered on 18 Aug 2010, 08:03 AM
Hello Timo,

To the best of my knowledge it is not possible to make a property readonly when using Html.EditorFor. There is the [ReadOnly(true)] attribute but it does not seem to work with Html.EditorFor. I guess the only option is to create an EditorTemplate as Jigar suggested.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
JULIA
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
JULIA
Top achievements
Rank 1
Jigar
Top achievements
Rank 1
Share this question
or