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

How to set GridTemplateColumn to readonly and still get value for update

3 Answers 494 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Harri
Top achievements
Rank 1
Harri asked on 31 Aug 2020, 11:00 AM

Hi

We have Batch editable grid with GridBoundColumns and GridTemplateColumns because of need checkbox / combobox. Some columns are editable and some read only by default or set read only by user rights to do changes (on page loading events set column to readonly). All possible changeable columns are set to ForceExtractValue="true" that those are available on ObjectDataSource updating event parameters. But when GridTemplateColumn is changed to readonly, value is not there anymore. What we do wrong?

 

Here is aspx file columns both normal (and always readonly column) and template column (changed code behind to read only):

 

01.<telerik:GridBoundColumn DataField="PrintHeader" HeaderText="Print Header" SortExpression="PrintHeader" UniqueName="PrintHeader" FilterControlAltText="Filter PrintHeader column" ReadOnly="True" HeaderStyle-Width="200px" ItemStyle-Width="200px" ForceExtractValue="Always"></telerik:GridBoundColumn>
02. 
03.<telerik:GridTemplateColumn UniqueName="ApprovalInspectionPoint" DataField="ApprovalInspectionPoint" HeaderText="Insp. point" FilterControlAltText="Filter ApprovalInspectionPoint column" SortExpression="ApprovalInspectionPoint" ColumnGroupName="Record" ForceExtractValue="Always">
04.    <HeaderStyle Width="50px"></HeaderStyle>
05.    <ItemStyle Width="40px"></ItemStyle>
06.    <ItemTemplate>
07.        <telerik:RadLabel ID="lblApprovalInspectionPoint" runat="server" Text='<%# Eval("ApprovalInspectionPoint") %>' Width="40px"></telerik:RadLabel>
08.    </ItemTemplate>
09.    <EditItemTemplate>
10.        <telerik:RadComboBox ID="cmbApprovalInspectionPoint" runat="server" DataSourceID="odsInspectionPoint" DataTextField="COD" DataValueField="COD" Width="40px"></telerik:RadComboBox>
11.    </EditItemTemplate>
12.</telerik:GridTemplateColumn>

 

Here are couple different users run situation for same row from ObjectDataSource OnUpdating event.

Event code from where debug watch compare lists:

1.protected void odsITP_Updating(object sender, ObjectDataSourceMethodEventArgs e)
2.{
3.    ITP rowToUpdate = e.InputParameters[0] as ITP;
4.    ITP rowToCompare = ....  //Data from DB
5....

 

Result from debug watch (some formatting to show properly) with user where all are enabled:

1.rowToUpdate.ID      43579       int?
2.rowToCompare.ID     43579       int?
3.rowToUpdate.PrintHeader     "Production Welding Monitoring"     string
4.rowToCompare.PrintHeader        "Production Welding Monitoring"     string
5.rowToUpdate.ApprovalInspectionPoint     "H"     string
6.rowToCompare.ApprovalInspectionPoint    "H"     string
7.(grITPS.Columns.FindByUniqueName("PrintHeader") as GridBoundColumn).ReadOnly        true        bool
8.(grITPS.Columns.FindByUniqueName("ApprovalInspectionPoint") as GridTemplateColumn).ReadOnly     false       bool

 

 

And result with user where that approvalcheckpoint column is read only (compare rows 5 and 8 to above):

1.rowToUpdate.ID      43579       int?
2.rowToCompare.ID     43579       int?
3.rowToUpdate.PrintHeader     "Production Welding Monitoring"     string
4.rowToCompare.PrintHeader        "Production Welding Monitoring"     string
5.rowToUpdate.ApprovalInspectionPoint     null        string
6.rowToCompare.ApprovalInspectionPoint        "H"     string
7.(grITPS.Columns.FindByUniqueName("PrintHeader") as GridBoundColumn).ReadOnly        true        bool
8.(grITPS.Columns.FindByUniqueName("ApprovalInspectionPoint") as GridTemplateColumn).ReadOnly     true        bool

 

Regards

Harri

3 Answers, 1 is accepted

Sort by
0
Accepted
Attila Antal
Telerik team
answered on 03 Sep 2020, 10:22 AM

Hi Harri,

ReadOnly will not only prevent the user from editing the column but will also tell the Grid to exclude it from the Edited data sent to the server. Therefore, the information of the ReadOnly columns will not be posted to the server.

If you still want to access the values of the cells/controls of the ReadOnly column, you will need to access them manually. Check out the Accessing Values and Controls article for instructions.

Regards,
Attila Antal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Harri
Top achievements
Rank 1
answered on 03 Sep 2020, 11:33 AM

Thanks for answer

I already did this in other way (not easily all possible at once but with user right specific only from that user editable columns), but your answer race a question. Why GridBoundColumn with ReadOnly=True does not exclude value as it should do as I understand from your answer?

Regards
Harri

0
Accepted
Attila Antal
Telerik team
answered on 08 Sep 2020, 10:54 AM

Hi Harri,

I was referring to the Template columns. Bound columns are built-in and the Grid is aware of the Controls inside them. A Template column, on the other hand, is abstract to the Grid since it could contain absolutely anything the developer decides to add. The Grid would not know about that, and therefore, it can't control it the same way it would control a bound column. Data bound in Template columns will not be available if ReadOnly property is set to True, and that is regardless of the ForceExtractValue property.

Regards,
Attila Antal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Harri
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Harri
Top achievements
Rank 1
Share this question
or