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

Delay persisting changes to Grid until user presses Submit button

1 Answer 15 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gregg
Top achievements
Rank 1
Gregg asked on 01 Jul 2009, 05:16 PM
Is it possible to use Rad Grid and its Insert/Update/Delete functionality such that the Insert/Update/Deletes done on the client side are only temporary and any changes (Insert/Update/Deletes) are not persisted to the server, e.g. to a database, until the user clicks a Submit button on the same page which contains the Grid? 

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 02 Jul 2009, 09:17 AM
Hi,

Use a dataset as the source of your grid and manipulate it to store temporary changes.Later on when you want to submit the changes to the database you can retrieve the data from the dataset.You can ajaxify the grid using a RadAjaxManager. Here is an example of how you can achieve this:

CS:
 protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) 
        { 
            GridEditableItem eeditedItem = e.Item as GridEditableItem; 
            DataTable ordersTable = this.OrdersData.Tables["Orders"]; 
 
            //Locate the changed row in the DataSource 
            DataRow[] changedRows = ordersTable.Select("OrderIDOrderID = " + editedItem.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["OrderID"]); 
 
            if (changedRows.Length != 1) 
            { 
                RadGrid1.Controls.Add(new LiteralControl("Unable to locate the Order for updating.")); 
                e.Canceled = true
                return; 
            } 
 
            //Update new values 
            Hashtable newnewValues = new Hashtable(); 
            //The GridTableView will fill the values from all editable columns in the hash 
            e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem); 
 
            DataRow changedRow = changedRows[0]; 
            changedRow.BeginEdit(); 
            try 
            { 
                foreach (DictionaryEntry entry in newValues) 
                { 
                    changedRow[(string)entry.Key] = entry.Value; 
                } 
                changedRow.EndEdit(); 
            } 
            catch (Exception ex) 
            { 
                changedRow.CancelEdit(); 
                RadGrid1.Controls.Add(new LiteralControl("Unable to update Orders. Reason: " + ex.Message)); 
                e.Canceled = true
            } 
 
            //Code for updating the database can go here... 
            this.OrdersData.Tables["Orders"].AcceptChanges(); 
            RadGrid1.Controls.Add(new LiteralControl("Order " + changedRow["OrderID"] + " updated")); 
        } 


Thanks,
Princy
Tags
Grid
Asked by
Gregg
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or