RadGrid Batch Editing / Updating Issue. newValues hashtable shows changes when I do not make changes.

2 Answers 36 Views
Grid
Roger
Top achievements
Rank 2
Iron
Iron
Iron
Roger asked on 13 Oct 2021, 08:28 PM

I have a radgrid that gets it's data from a Stored Proc and a gridview.DataBind() .  It works as expected, but when I edit one cell and SAVE changes utilizing the Save Changes Command Button, all my "Editable" columns now seem to have newValues even if I did not edit them.

gvResults.DataSource = DAL.ExecuteDataset(30, "GetProductionDateTrackingInfo", parms.ToArray());
gvResults.DataBind();

 

Example one column is a RadDatePicker with a MinDate

 <EditItemTemplate>
                        <telerik:RadDatePicker RenderMode="Lightweight" ID="MB_Production_DatePicker" MinDate="1/1/1970" runat="server" DbSelectedDate='<%# Bind("MB_Production_Date") %>'> </telerik:RadDatePicker>
                    </EditItemTemplate>

The newValues hashtable has this column as changed eventhough I didn't click in it.

How do I set the grid to No changes so only when a user clicks on a cell and changes it shows up in the newValues hashtable?

 

2 Answers, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 18 Oct 2021, 12:43 PM

Hi Roger,

You will need to change the data binding to either Declarative data source control or Programmatic DataBinding with NeedDataSource event, see How to bind RadGrid properly on server-side.

Binding data to RadGrid using the DataSource property and calling the DataBind() method is considered as Simple Data-binding. This does not support functionalities such as:

  • Inserting, deleting, and updating records through custom edit forms (WebUserControl or FormTemplate)
  • Grouping
  • Hierarchy relations
  • Filtering
  • Sorting
  • Paging

With the proper data binding, the CRUD operations will also be consistent.

Regards,
Attila Antal
Progress Telerik

Remote troubleshooting is now easier with Telerik Fiddler Jam. Get the full context to end-users' issues in just three steps! Start your trial here - https://www.telerik.com/fiddler-jam.
Roger
Top achievements
Rank 2
Iron
Iron
Iron
commented on 18 Oct 2021, 01:17 PM

Attila,

I need to fill in the grid after a few selections on the page are done which allow for a dynamic SQL to fill the grid.  I am not sure how to do that as all examples I see do not show any such way of filling the grid.

I did try to use the "Rebind()" after getting the items filled on the grid, but same result, seeing more items in the newValues for all columns even when I did not change them.

Need to see a way we can  call the NeedDatasource now to fill the grid with parameters set from page.

0
Attila Antal
Telerik team
answered on 21 Oct 2021, 07:49 AM

Roger,

Create a Property that will hold the data in the session and use it in the NeedDataSource event of the Grid. When you make one or more selections on the page, you will update the Session and call the RadGrid1.Rebind(). That will cause the Grid to raise the NeedDataSource event, and eventually pull the new data from the session.

Here is an example that uses the same approach: Improve RadGrid performance by reducing the number of slow queries to the database

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/.

Roger
Top achievements
Rank 2
Iron
Iron
Iron
commented on 21 Oct 2021, 03:57 PM

My workaround was to add all the editable  grid columns to the DataKeyNames then do a is newValue != oldValue on the BatchEditCommand Update.  If they were != then I know it was changed.

I had to check each Value to see if it was changed from OLD but at least all the columns were then added to both the oldValue and newValues hashtables. 

This did the trick.  I then did my onw update statement to the SQL table via stored proc.

Example:

  if(newValues["MR_Production_Date"] != oldValues["MR_Production_Date"])
                    update MR_Production_Date in my SQL

Attila Antal
Telerik team
commented on 22 Oct 2021, 09:00 AM

Roger,

First I understood that the Grid was marking all columns as "dirty" as if their values were changed, but now I realize you are talking about the Hashtable collections. Yes, the OldValues and NewValues will always be populated, so if there aren't any changes, they will look identical. Otherwise, the NewValues hash table will contain the new changes.

Comparing the Old and New values before including them to the SQL Query is the correct approach. We have that mentioned in the Batch Editing Server-side API article. However, you do not need to add all Columns to the DataKeyNames collection. Just make sure that you have the proper data binding as I have mentioned earlier.

Roger
Top achievements
Rank 2
Iron
Iron
Iron
commented on 22 Oct 2021, 07:49 PM

Attila,

In order to have all of the columns show up in both the newValues and oldValues hashtable I did need to add them to the datakeys.  

If I did not, most all of the columns would not show up in the oldValues, but would show up in the newValues, so I could not compare them.  This was the only solution I could find to work.

Attila Antal
Telerik team
commented on 27 Oct 2021, 10:04 AM

Roger, why don't you share the complete implementation so that I can look at it? Without seeing the configuration it is hard to tell what is going on.
Tags
Grid
Asked by
Roger
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Attila Antal
Telerik team
Share this question
or