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

RadGrid Batch Update not seeing the newValues

2 Answers 268 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 29 Sep 2020, 05:47 PM

Thanks for help with this.

I am passing a loaded datatable using a Session (Datatable) variable from another form to another form.  I then copy the Session (Datatable) variable to a local datatable and then bind this datatable  to a radgrid. 

 

When a cell changes value and the "Save Changes" is clicked.  All runs well but the entry.Value (newValue) is still showing old value.
changedRows[0][(string)entry.Key] = entry.Value;  

Also, I tried to loop through the grid in the same routine but I still see the old value as well.  I included the HTML code along with the update subroutine.  

 

<telerik:RadGrid ID="grdIncome" runat="server" AllowAutomaticUpdates="True" AllowMultiRowSelection="True" Font-Names="Arial" 
                                OnColumnCreated="grdIncome_OnColumnCreated" OnItemDataBound="grdIncome_ItemDataBound" 
                                OnUpdateCommand="grdIncome_UpdateCommand" 
                                OnItemUpdated="grdIncome_ItemUpdated" OnEditCommand="grdIncome_EditCommand" OnNeedDataSource="grdIncome_NeedDataSource1"
                                Skin="Silk" Width="100%" Font-Size="Small" ShowFooter="True"  GridLines="None" AllowPaging="true" PageSize="20"  >
                                <MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="AccountID"
                                    AutoGenerateColumns="true" HorizontalAlign="NotSet" EditMode="InPlace" >
                                    <BatchEditingSettings  EditType="Cell" HighlightDeletedRows="true"/>

                                    <Columns>
                                                                                        
                                    </Columns>
                                </MasterTableView>

                            </telerik:RadGrid> 

 

 

        protected void grdIncome_UpdateCommand(object sender, GridCommandEventArgs e)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;

            if (!UpdateRow(editedItem))
            {
                e.Canceled = true;
            }
        }

        private bool UpdateRow(GridEditableItem editableItem)
        {

            //Locate the changed row in the DataSource
            DataRow[] changedRows = SessionDataSource.Select(string.Format("AccountID = {0}", editableItem.GetDataKeyValue("AccountID")));

            if (changedRows.Length != 1)
            {
                this.Label1.Text += "Unable to locate the Income Account for updating.";
                return false;
            }

            for (int i = 0; i < grdIncome.MasterTableView.Items.Count; i++)
            {
                GridDataItem dataItem = (GridDataItem)grdIncome.MasterTableView.Items[i];
                string strItemId = dataItem.GetDataKeyValue("AccountID").ToString();
                Console.Write(dataItem["MM01"].Text);
            }


            //Update new values
            Hashtable newValues = new Hashtable();
            editableItem.OwnerTableView.ExtractValuesFromItem(newValues, editableItem);
            changedRows[0].BeginEdit();
            try
            {
                foreach (DictionaryEntry entry in newValues)
                {
                    changedRows[0][(string)entry.Key] = entry.Value;
                }
                changedRows[0].EndEdit();
            }
            catch (Exception ex)
            {
                changedRows[0].CancelEdit();
                Label1.Text += string.Format("Unable to update Orders. Reason: {0}", ex.Message);
                return false;
            }

            return true;
        }

2 Answers, 1 is accepted

Sort by
0
Accepted
Attila Antal
Telerik team
answered on 02 Oct 2020, 03:38 PM

Hi John,

The code you shared looks similar to the example from Update all, individual or selected rows using RadGrid with InPlace edit mode article and based on your description, sounds like values are not passed to the Grid correctly. 

If you're using the built-in columns, ensure that they have the DataField property pointing on the field in the DataSource, or if you are using Template columns, the Value/Text/SelectedItem/SelectedDate needs to be bound using the two-way binding expression Bind() because the Eval() is one-way binding mainly to display data.

<telerik:GridTemplateColumn>
    <ItemTemplate>
        <%--Eval is to display data only--%>
        <asp:Label ID="Label1" runat="server" Text='<%# Eval("ContactName") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
        <%--Bind is to indicate that values must be processed in the CRUD operations--%>
        <telerik:RadTextBox ID="RadTextBox1" runat="server" Text='<%# Bind("ContactName") %>'></telerik:RadTextBox>
    </EditItemTemplate>
</telerik:GridTemplateColumn>

 

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
John
Top achievements
Rank 1
answered on 02 Oct 2020, 04:30 PM
Thank you Attila 
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
John
Top achievements
Rank 1
Share this question
or