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

Save Grid

9 Answers 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stefan
Top achievements
Rank 2
Stefan asked on 28 Jun 2013, 01:42 PM
I have a grid I am trying to do a batch update but I need to loop through the grid and save all the values.  I need to be able to get any value that was update along with values that were left alone.  Is this possible?  All I have been able to find is how to get new values or the old values.  I need them both at the same time in a loop through the grid so when my user hits the save button I can save the entire grid to a new database table.  vb.net.

Thanks,

9 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 03 Jul 2013, 07:55 AM
Hi Stefan,

You can use the new Batch editing functionality of RadGrid to achieve the requested functionality:
http://www.telerik.com/help/aspnet-ajax/grid-batch-editing.html

You can find a live example here:
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/batchediting/defaultcs.aspx

Hope this helps.

Regards,
Eyup
Telerik
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 the blog feed now.
0
Stefan
Top achievements
Rank 2
answered on 03 Jul 2013, 03:42 PM
This does not work for me becasue I am using advanced databinding and I can not get any of the events to fire except for BatchEditCommand.  Is there a way to loop through the grid in this event to retrieve the old and new values of the grid?  Or if it is possible to fire the ItemDeleted or ItemUpdated events with advanced databinding please let me know how.
0
Eyup
Telerik team
answered on 08 Jul 2013, 01:41 PM
Hi Stefan,

Please try the following approach:
protected void RadGrid1_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
{
    foreach (GridBatchEditingCommand command in e.Commands)
    {
        Hashtable oldValues = command.OldValues;
        Hashtable newValues = command.NewValues;
 
        foreach (string key in oldValues.Keys)
        {
            string value = oldValues[key].ToString();
        }
    }
}

Or:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    GridBatchEditingEventArgument argument = e.CommandArgument as GridBatchEditingEventArgument;
    if (argument != null)
    {
        Hashtable oldValues = argument.OldValues;
        Hashtable newValues = argument.NewValues;
 
        foreach (string key in oldValues.Keys)
        {
            string value = oldValues[key].ToString();
        }
    }
}

That should do the trick.

Regards,
Eyup
Telerik
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 the blog feed now.
0
sharon
Top achievements
Rank 1
answered on 19 Jan 2016, 10:28 AM

Hi!

  I am using batchEditUpdate and I have tried methods you provided above, but the OldValues for both methods only contains one element, the DataKeyNames.  Why are there no columns of the grid in the OldValues?  I need compare some fields of OldValues and NewValues.  Any suggestions?

Thanks in advance!

Sharon

0
Stefan
Top achievements
Rank 2
answered on 20 Jan 2016, 05:20 PM

Not Sure if this will help any but I use the BatchEditCommand sub of the Grid

        If IsPostBack Then
            For Each item As GridBatchEditingCommand In e.Commands
                Dim editedRow = item
                Dim EditCol = dgCompGrid.Columns
                Dim iRow As Int32

                var1= (item.Item.GetDataKeyValue("field1").ToString())
                var2 = (item.Item.GetDataKeyValue("field2").ToString())

                iRow = item.Item.ItemIndex
                For Each col As GridColumn In dgCompGrid.MasterTableView.Columns
                    If editedRow.NewValues(col.HeaderText) <> editedRow.OldValues(col.HeaderText) Then
                        iXSrcValue = col.HeaderText
                        ws.Update(var1, var2, editedRow.OldValues(col.HeaderText), Convert.ToDecimal(editedRow.NewValues(col.HeaderText)))
                    End If
                Next
            Next
End IF

0
sharon
Top achievements
Rank 1
answered on 21 Jan 2016, 03:56 AM

Hi! Stefan,

   Thank you for replying, but my problem is there are no elements (columns in the grid) in the Telerik specific variable - OldValues.

Thanks!

Sharon

 

      

0
Eyup
Telerik team
answered on 22 Jan 2016, 08:41 AM
Hi Sharon,

Could you verify that you are not using DataBind() to bind the grid? Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Exporting, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
Declarative DataSource
Programmatic Data Binding


Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
sharon
Top achievements
Rank 1
answered on 25 Jan 2016, 09:05 AM

Hi! Eyup,

  I use NeedDataSource, so, I think i am using Advanced databinding.

Thanks,

Sharon

0
Eyup
Telerik team
answered on 28 Jan 2016, 06:50 AM
Hi Sharon,

Yes, Advanced databinding = Programmatic databinding = NeedDataSource event handler.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Stefan
Top achievements
Rank 2
Answers by
Eyup
Telerik team
Stefan
Top achievements
Rank 2
sharon
Top achievements
Rank 1
Share this question
or