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

ReadOnly Field causes no Updates on RadGrid

10 Answers 123 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marcio Nascimento
Top achievements
Rank 1
Marcio Nascimento asked on 30 Jan 2012, 06:13 PM
Hello Everyone,

I have two questions about Radgrid that I never understood completely. I'm using the new telerik 2011.3.1305.40. ASP.NET AJAX.
I Send a download Link with a simple example to illustrate my doubts. http://www.omnilab.com.br/documentos/ReadOnlyFields.rar
In the example I have one table with 4 fields. One of them is the primary key and identity field.

When I run the example, all happens fine, I can Edit and Update the table, however:
  1. When I make the field "id_movie" readonly, the table no longer updates. Why this happens? How can I solve this?
  2. If I change the type of field "control" to bit (to enable checkbox), the table no longer updates. Why this happens? How can I solve this?

I appreciate anyone to clarify those doubts to me.

Regards,
Marcio Nascimento

10 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 31 Jan 2012, 05:50 AM
Hello Marcio,

Setting ReadOnly property for a column checks whether the column editor is visible in edit mode. This property is only available for column types that allow editing. The ReadOnly property has no effect on whether the column appears in browser mode. Hope this helps.

-Shinu.
0
Marcio Nascimento
Top achievements
Rank 1
answered on 31 Jan 2012, 05:11 PM
Hi Shinu,

Thanks for your answer.
All my columns are available for editing, except the primary key fileld, of course.
For example, I have a column named "id_movie" that when I check the ReadOnly property to True, the Radgrid cannot update the other field on the table. I cannot find if this is right or if I'm doing something wrong.

Marcio Nascimento
0
Tsvetina
Telerik team
answered on 03 Feb 2012, 02:08 PM
Hello Marcio,

This is not expected behavior. As you can see here, by default the ReadOnly property prevents only changes in the column which has it set:
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/editondblclick/defaultcs.aspx

Can you paste your grid's update logic, so we can look for any problems with it?

Greetings,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Marcio Nascimento
Top achievements
Rank 1
answered on 03 Feb 2012, 09:05 PM
Hello Tsvetina,

Thanks for your answer. My grid logic follows below:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True"
            AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
            AutoGenerateColumns="False" CellSpacing="0" DataSourceID="SqlDataSource1"
            GridLines="None">
            <ClientSettings>
                <Selecting AllowRowSelect="True" />
            </ClientSettings>
<MasterTableView DataKeyNames="id_register" DataSourceID="SqlDataSource1">
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
 
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
 
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
 
    <Columns>
        <telerik:GridBoundColumn DataField="id_register" DataType="System.Int32"
            FilterControlAltText="Filter id_register column" HeaderText="id_register"
            ReadOnly="True" SortExpression="id_register" UniqueName="id_register">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="id_movie" DataType="System.Int32"
            FilterControlAltText="Filter id_movie column" HeaderText="id_movie"
            ReadOnly="True" SortExpression="id_movie" UniqueName="id_movie">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="register_number"
            FilterControlAltText="Filter register_number column"
            HeaderText="register_number" SortExpression="register_number"
            UniqueName="register_number">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="control" DataType="System.Int32"
            FilterControlAltText="Filter control column" HeaderText="control"
            SortExpression="control" UniqueName="control">
        </telerik:GridBoundColumn>
        <telerik:GridEditCommandColumn FilterControlAltText="Filter EditCommandColumn column">
        </telerik:GridEditCommandColumn>
    </Columns>
 
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
</MasterTableView>
 
<FilterMenu EnableImageSprites="False"></FilterMenu>
        </telerik:RadGrid>
    </div>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConflictDetection="CompareAllValues"
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        DeleteCommand="DELETE FROM [Movie_Register] WHERE [id_register] = @original_id_register AND (([id_movie] = @original_id_movie) OR ([id_movie] IS NULL AND @original_id_movie IS NULL)) AND (([register_number] = @original_register_number) OR ([register_number] IS NULL AND @original_register_number IS NULL)) AND (([control] = @original_control) OR ([control] IS NULL AND @original_control IS NULL))"
        InsertCommand="INSERT INTO [Movie_Register] ([id_movie], [register_number], [control]) VALUES (@id_movie, @register_number, @control)"
        OldValuesParameterFormatString="original_{0}"
        SelectCommand="SELECT * FROM [Movie_Register]"
        UpdateCommand="UPDATE [Movie_Register] SET [id_movie] = @id_movie, [register_number] = @register_number, [control] = @control WHERE [id_register] = @original_id_register AND (([id_movie] = @original_id_movie) OR ([id_movie] IS NULL AND @original_id_movie IS NULL)) AND (([register_number] = @original_register_number) OR ([register_number] IS NULL AND @original_register_number IS NULL)) AND (([control] = @original_control) OR ([control] IS NULL AND @original_control IS NULL))">
        <DeleteParameters>
            <asp:Parameter Name="original_id_register" Type="Int32" />
            <asp:Parameter Name="original_id_movie" Type="Int32" />
            <asp:Parameter Name="original_register_number" Type="String" />
            <asp:Parameter Name="original_control" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="id_movie" Type="Int32" />
            <asp:Parameter Name="register_number" Type="String" />
            <asp:Parameter Name="control" Type="Int32" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="id_movie" Type="Int32" />
            <asp:Parameter Name="register_number" Type="String" />
            <asp:Parameter Name="control" Type="Int32" />
            <asp:Parameter Name="original_id_register" Type="Int32" />
            <asp:Parameter Name="original_id_movie" Type="Int32" />
            <asp:Parameter Name="original_register_number" Type="String" />
            <asp:Parameter Name="original_control" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>

Thanks for your help.

Marcio Nascimento
0
Tsvetina
Telerik team
answered on 08 Feb 2012, 01:16 PM
Hello Marcio,

I managed to replicate the problem using Northwind DB and your setup. It seems something in the WHERE clause of your UPDATE command prevents the update because when I simplified it to:
UpdateCommand="UPDATE [Orders] SET [CustomerID] = @CustomerID, [ShipCity] = @ShipCity, [ShipCountry] = @ShipCountry WHERE [OrderID] = @original_OrderID"
 instead of:
UpdateCommand="UPDATE [Orders] SET [CustomerID] = @CustomerID, [ShipCity] = @ShipCity, [ShipCountry] = @ShipCountry WHERE [OrderID] = @original_OrderID AND (([CustomerID] = @original_CustomerID) OR ([CustomerID] IS NULL AND @original_CustomerID IS NULL)) AND (([ShipCity] = @original_ShipCity) OR ([ShipCity] IS NULL AND @original_ShipCity IS NULL)) AND (([ShipCountry] = @original_ShipCountry) OR ([ShipCountry] IS NULL AND @original_ShipCountry IS NULL))"

the updates started working.

Also, I tried using the SqlDataSource designer to autogenerate statements and parameters for operations with optimistic concurrency and it again worked.
Therefore, my advice is to look closely at the UPDATE command and also generate one through the designer and see what are the differences and whether you could allow using the auto-generated command.


Regards,
Tsvetina
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Marcio Nascimento
Top achievements
Rank 1
answered on 09 Feb 2012, 02:22 AM
Hi Tsvetina,

Your modification works, but only if you don't have any readonly fields. For example, in your code, if you set the property readonly to the field "CustomerID", when you update the table, the field CustumerID becomes NULL.
I must say here that what I'm intriguing is that I create my example using only the designer, never touched the code.

Any other ideas?

Regards,

Marcio Nascimento
0
Tsvetina
Telerik team
answered on 13 Feb 2012, 02:29 PM
Hi Marcio,

I got your point on this. However, the described problem with the CustomerID field is an expected one - the UPDATE command tries to set the value of the CustomerID field, while at the same time it is ReadOnly, so it cannot be extracted from RadGrid. This leads to a null value being set through the update.

The idea of having ReadOnly fields is to not update them at all, as it would be with OrderID.

So there are two options:
1) Modify the update statement, so that it does not try to update the ReadOnly fields.
2) Instead of making non-key fields ReadOnly, you can disable/hide the respective edit textbox during edit, as shown in this demo:
http://demos.telerik.com/aspnet-ajax/grid/examples/automaticoperations/efdatabinding/defaultcs.aspx


Kind regards,
Tsvetina
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Andrew
Top achievements
Rank 1
Veteran
answered on 27 Jun 2012, 02:46 PM
Hi,

I am having the same type of issue but I am using an "OpenAccessLinqDataSource"
I have a grid that when in edit mode the user can change some fields but the db table contains fields that are not in the grid when the update happens the fields that are not in the grid lose there values (overwriten).

I have tried adding the field to the grid like:
<telerik:GridBoundColumn DataField="Keywords" DataType="System.String" AllowFiltering="false" AllowSorting="false" ReadOnly="True" UniqueName="Keywords" Display="false" />

hoping the value would then be saved and the user would still not see the data but it did not work.

Any ideas?

ORM: v2012.1.301.2
RadControls: 2012.1.411.40

0
Marcio Nascimento
Top achievements
Rank 1
answered on 27 Jun 2012, 03:35 PM
Hi Andrew, I solve this issue using Linq to sql. Works like a charm! Regards, Marcio Nascimento
0
Andrew
Top achievements
Rank 1
Veteran
answered on 27 Jun 2012, 05:00 PM
Thanks,

But it must be a bug with the datasource, maybe I will open a ticket with them.
I fixed it like this:

protected void ArticlesData_Updating(object sender, Telerik.OpenAccess.Web.OpenAccessLinqDataSourceUpdateEventArgs e)
        {
            ((Article)e.NewObject).Keywords = ((Article)e.OriginalObject).Keywords;
            ((Article)e.NewObject).Abstract = ((Article)e.OriginalObject).Abstract;
            ((Article)e.NewObject).Notes = ((Article)e.OriginalObject).Notes;
        }

Tags
Grid
Asked by
Marcio Nascimento
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Marcio Nascimento
Top achievements
Rank 1
Tsvetina
Telerik team
Andrew
Top achievements
Rank 1
Veteran
Share this question
or