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

new values not present when batch updating grid

2 Answers 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 08 Jan 2009, 07:50 PM
I am having a problem retrieving the edited values from a radgrid control that I am processing in batch mode.  The user can enter edit mode and change multiple rows and then click a button to initiate the batch save.  I can not use a CommandItemTemplate and place the control that initiates the update in the grid header.

I am placing the grid control in edit mode by executing the following code on a button click:

Protected Sub btnFollowupEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFollowupEdit.Click
    Me.btnFollowupCancel.Visible = True
    Me.btnFollowupEdit.Visible = False
    Me.btnFollowupSave.Enabled = True

    For Each item As GridItem In radgFollowUp.MasterTableView.Items
        If TypeOf item Is GridEditableItem Then
            Dim editableItem As GridEditableItem = CType(item, GridDataItem)
            editableItem.Edit = True
        End If
    Next
    radgFollowUp.Rebind()
End Sub


This works correctly.

When clicking a button to save the edited values in the grid I execute the following code:

 

Protected Sub btnFollowupSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFollowupSave.Click
    For Each editedItem As GridEditableItem In radgFollowUp.EditItems
        If TypeOf editedItem Is GridEditableItem Then
            Dim theItem As GridEditableItem = CType(editedItem, GridEditableItem)
            Dim newValues As New Hashtable()
             'The GridTableView will fill the values from all editable columns in the hash
            theItem.OwnerTableView.ExtractValuesFromItem(newValues, theItem)

            '***
            'The newValues hashtable contains the original values for the editable controls, not the changed values

            ' ... do stuff here to save the data
        End If
    Next
end sub

 


Can anyone tell me how to access the new(changed) values for the edited controls.  I may have a cast wrong since I have a different event argument from the examples I have found.

Thanks for your help ,

John

 

 

 

 

 

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 09 Jan 2009, 06:31 AM
Hi John,

I tried with the above code and batch update is working fine on my end. Have you by any chance calling a Rebind method in any of the events which will be fired prior to the click event of the Save(btnFollowupSave) button. If so try removing the Rebind method and see whether Update is taking place. Invoking a Rebind method prior to the Update operation will make all the changes you made in the edit mode to be lost.

Here is the code which I tried on my end:
 
protected void LinkButton1_Click(object sender, EventArgs e)  
    {  
        foreach (GridEditableItem editedItem in RadGrid1.EditItems)  
        {  
            Hashtable newValues = new Hashtable();  
            editedItem.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);  
            SqlDataSource1.UpdateCommand = String.Format("Update Products SET ProductName='{0}' WHERE ProductID='{1}'", newValues["ProductName"], editedItem.GetDataKeyValue("ProductID").ToString());  
            SqlDataSource1.Update();  
            editedItem.Edit = false;  
        }  
  
  
         
        RadGrid1.Rebind();  
    }  
      


Regards
Shinu
0
John
Top achievements
Rank 1
answered on 09 Jan 2009, 01:59 PM

Thanks Shinu!

You were correct, the page was being rebound. I am taking over this code from someone else and didn't think to check for that happening.

 

Good catch!

Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
John
Top achievements
Rank 1
Share this question
or