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

Radgrid with AllowMultiRowEdit loses values

11 Answers 542 Views
Grid
This is a migrated thread and some comments may be shown as answers.
George
Top achievements
Rank 1
George asked on 02 Apr 2009, 10:14 AM
Hallo,
first of all congratulations for you suite, i find it to be the best asp.net suite ever!

I have the following problem,
i want the user to be able to perform multiple, concurrent edits in a radgrid and the update them all together.
I found a sample of yours regarding "batch update" which works perfect and i have set the AllowMultiRowEdit="True" so that the user can edit multiple rows.

The problem is that if a user begins editing one row, changes some data and THEN begins editing another row, although both of these rows will be in edit mode, all the changes before  the last "Edit" Command will be lost!

I have checked this with your samples too and they have the same malfunction ( or functionality :)  ).

I tried to get the existing data from the previous editing rows inside the RadGrid1_ItemDataBound event like this:

  
            if (e.Item is GridDataItem && e.Item.IsInEditMode) 
            { 
                GridEditableItem dataItem = e.Item as GridEditableItem; 
                dataItem["AutoGeneratedEditColumn"].Controls[0].Visible = false; 
 
                Hashtable newValues = new Hashtable(); 
                e.Item.OwnerTableView.ExtractValuesFromItem(newValues, dataItem); 
 
                string sPosition = (dataItem["Position"].Controls[0] as System.Web.UI.WebControls.TextBox).Text; 
            } 

Neither newValues nor sPosition has the changed values for the previously edited items.
They all have the original values.

Is there any workaround?

Thanks in advance!


11 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 06 Apr 2009, 12:13 PM
Hello George,

The described behavior is actually expected. If the user edits several rows and then updates only one, or tries to edit another row, the grid will rebind itself and all modified data on client side will be lost. I can suggest you allow the users edit and update only selected rows. Please examine this online demo which implements this approach.

You cannot retrieve the client modifications in ItemDataBound event handler, because the grid does not know about these changes when it rebinds itself. You can write some JavaScript functionality in order to watch whether the data is modified. Here is an online demo which illustrates similar functionality.

Best regards,
Georgi Krustev
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Russ
Top achievements
Rank 1
answered on 15 Apr 2009, 03:32 PM
There must be some way around this?  Otherwise, it makes the AllowMultiRowEdit kind of pointless.

I can get as far as extracting my new values in the code, but I'm just stuck at how to update the matching data item in the grid..

       protected void radgrid1_ItemCommand(object source, GridCommandEventArgs e)  
        {  
            // if user is editing an item, try to keep the latest state of changes for other items in edit mode also  
            if (e.CommandName == "Edit")  
            {  
                foreach (GridDataItem dataItem in radgrid1.EditItems)  
                {  
                    Hashtable editValues = new Hashtable();  
                    e.Item.OwnerTableView.ExtractValuesFromItem(editValues, dataItem);  
                                          
 
                    // tried the lines below, but it doesn't work because it just updates the control in the current edititem (which has the new values, not old).  
                    TextBox itemValue = (dataItem["TASK_DESCRIPTION"].Controls[0] as TextBox);  
                    itemValue.Text = editValues["TASK_DESCRIPTION"].ToString();  
 
 
                    // how to access and update the actual data item from here???  
                }  
 
            }  
 


0
Georgi Krustev
Telerik team
answered on 16 Apr 2009, 12:48 PM
Hello Russell,

I will suggest you to examine this online help article, which shows how to implement the requested behavior.
I just want to draw your attention to the end of the suggested article. There is a method which describes how to hide the Update and Cancel buttons in order to avoid any misunderstanding by the user. This code will work only if you use the "In-Place" edit mode. If you are using EditTemplate for editing of the row, you need to modify like so to hide the buttons:
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode) //if the item is a GridEditFormItem 
        { 
            var item = e.Item as GridEditFormItem; 
            var update = e.Item.FindControl("UpdateButton"as Button; 
            var cancel = e.Item.FindControl("CancelButton"as Button; 
 
            update.Visible = false
            cancel.Visible = false
}} 

Kind regards,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Russ
Top achievements
Rank 1
answered on 16 Apr 2009, 02:54 PM
That was what I needed, thank you.  I had scanned the article earlier, but missed a piece towards the end, 

For anyone else that might read this post (and if George is still following it), my fix was basically placing something like this in place of my last code snippet:

// first must declare a public DataTable in the code (similar to article)  
 
protected void radgrid1_ItemCommand(object source, GridCommandEventArgs e)     
{     
    // if user is editing an item, try to keep the latest state of changes for other items in edit mode also     
    if (e.CommandName == "Edit")     
    {     
        foreach (GridDataItem dataItem in radgrid1.EditItems)     
                {     
 
            // get the old row in the DataTable  
            string myKeyField = "ROW_ID";  
            string sqlSelect = "ROW_ID = '" + editedItem.GetDataKeyValue(myKeyField).ToString() + "'";  
            DataRow[] changedRows = myDataTable.Select(sqlSelect);  
 
            // get the updated fields  
            Hashtable editValues = new Hashtable();  
            //The GridTableView will fill the values from all editable columns in the hash  
            editedItem.OwnerTableView.ExtractValuesFromItem(editValues, editedItem);  
 
            // update the datatable row (note: this is not the actual database table)  
            DataRow changedRow = changedRows[0];  
            changedRow.BeginEdit();  
            try  
            {  
                foreach (DictionaryEntry entry in editValues)  
                {  
                    changedRow[(string)entry.Key] = entry.Value;  
                }  
                changedRow.EndEdit();  
            }  
            catch (Exception)  
            {  
                changedRow.CancelEdit();  
            }  
        }     
    }      
}   


0
Marc
Top achievements
Rank 1
answered on 31 Dec 2009, 11:58 PM
Instead of starting a new thread I'll comment on this one in need of Teleriks help.

At the begining of the documentation you say "A common scenario", if it is common, then the documentation needs to be much better. The problem is for those doing batch updates and allowing multirow edit (not necessarily multirow selection).  The two examples in the documentation are seperate, and there should be an example (a 3rd one) that combines the two in the context of the original posters problem.

For me, Im using an XML datasource and allowing multirow edit and batch update.  I have the batch update working, and the multirow edit working.  However, what doesnt work is the problem the original poster said, when a user edits a different row all the editable rows rebind.  This isnt very RAD to be honest and having to cludge together Russels provided code above (thanks BTW) along with the code from the demo is not Rapid Application Development and the end result is a very messy code behind.  It would be great if telerik could provide us with a RadGrid that actually does multirow edit and batch updating and at a minimum a good working example.
0
Sebastian
Telerik team
answered on 06 Jan 2010, 10:05 AM
Hello Marc,

Your comments are indeed meaningful and right on target. We will consider creating a new RadGrid online example (for the next major release of the product) which to illustrate how to perform client-side editing with batch updates and keep the information in the edited cells when editing more items.

The next release of our controls is planned in the beginning of March while a Beta version is scheduled in the middle of February. I hope that you will find the new sample useful and will be expecting your feedback on it.

Kind regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
mahima jain
Top achievements
Rank 1
answered on 21 Jan 2013, 10:25 AM
Hi all,

 i am working on multiple edit .... in my grid all rows are editable initial and there is an command button update all . when user clicks on that button all rows should be updated . i am facing problem in how to identify which rows are changed ... i mean suppose initialy i have 10 rows in edit mode and user modify only 5 rows ... then in my command how will i know that this row is modified or not ?

thanks in advance
0
Manoj
Top achievements
Rank 1
answered on 30 Jan 2013, 10:44 AM

Hello everyone,

           

            I have some problem with RadGrid multi row option, detailed as below. 

            I have One RadGrid with property allowmultirow=”true” & have embedded Usercontrol for edit operation.

            Have command item template with commandname = “UpdateAll” which will update all the rows which were in edit mode.

            In order to set row in edit mode, I have used edit command column, which is an imagebutton.

            So, whatever row user wants to edit, he will click on that imagebutton & the UserControl will be loaded with all the relevant data, user will do the same for all the rows which he wants to edit,

            And after that he will click on Updateall button, which will call the itemcommand event of grid and update all the data.

           

Now, the problem is while user click on edit command column my user control will be loaded with all its prerender, init event for the selected row.

After that suppose I make some changes in the some of the fields of user control, say we have textbox with user name which was initially loaded blank & I make changes it to ‘XYZ’.

Now again I select another row for edit operation. So again my user control will be loaded for this row as well as the previous row which I have selected.

So, whatever changes I have been made previously i.e. set user name = ‘XYZ’ from blank, will be again set to Blank,

WHY USERCONTROL IS LOADED FOR THE PREVIOUS ROW ????

That is my question, as it is degrading my applications performance,

As it is initialling user control for all the row which is in edit mode all the times, rather than calling it for the corresponding row selected and leaving other as it is. &

also initialize all the control and lose all the changes that I have made previously.


thnx in advance!! 
I am using 2010.2.929.35 verson, Is the problem been solved in new version ??

Manoj

0
Maria Ilieva
Telerik team
answered on 04 Feb 2013, 08:57 AM
Hello Manoj,

Could I kindly ask you to open a separate support ticket or a new forum post for the presented issue so we could better track the problem? Also note that providing your RadGrid markup as well as the related code behind will help us further investigate your scenario and do our best to isolate the root cause of the problem.

All the best,
Maria Ilieva
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
Manoj
Top achievements
Rank 1
answered on 13 Feb 2013, 09:12 AM

Hi! Maria Ilieva,

 

                I have already posted my forum @ following URL:

                http://www.telerik.com/community/forums/aspnet-mvc/grid/problem-with-radgrid-with-multirow-edit-in-user-control.aspx

                please see to it.

 
thanx,

                Manoj Panchal


0
Andrey
Telerik team
answered on 18 Feb 2013, 07:51 AM
Hi,

The described behavior is the expected behavior of RadGrid. AllowMultiRowEdit property is used to allow RadGrid to have more than one item in edit mode not to be able to edit the items independently. This behavior comes from the fact that when you put some item in Edit mode the Grid is rebound to the data and that is why the already opened editor are loaded with the value from the datasource and the user value is not persisted.

There are two possible work-arounds for this behavior:

 One is to put all the needed items in edit mode before starting to manipulate any data. Then when the user click some button you could extract all the values and update all the records at once.

The other approach is to hook the ItemDataBound event and to store the already entered values in some container object like List or some other collection. Another approach is to hold the entered value on the client.

@mahima

The only way to know which row is modified is to use some kind of marker. You need either to save the old state and compare it with the new or on the client to set some field with the index of edited items. Then on the server you could check whether the current item has an index equal to one of the items that you stored on the client.

Regards,
Andrey
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.
Tags
Grid
Asked by
George
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Russ
Top achievements
Rank 1
Marc
Top achievements
Rank 1
Sebastian
Telerik team
mahima jain
Top achievements
Rank 1
Manoj
Top achievements
Rank 1
Maria Ilieva
Telerik team
Andrey
Telerik team
Share this question
or