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

Get values in UpdateCommand Event

20 Answers 1436 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 02 Sep 2009, 11:12 PM
Hi,

How can I get / extract the values (text) out of the e.Item.DataItem-Object in an UpdateCommand of a RadGrid?

Here a screenshot which I made while debugging: http://www.pronux.ch/grid.JPG


Thanks for your help.

Mike




20 Answers, 1 is accepted

Sort by
0
SamJ
Top achievements
Rank 1
answered on 03 Sep 2009, 06:42 AM
HI,

You can check out the below articles elaborating on extracting values from RadGrid edit form and updating records:

http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/editmodes/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/extractvalues/defaultcs.aspx
http://www.telerik.com/help/aspnet-ajax/grdupdatinginplaceandeditforms.html
http://www.telerik.com/help/aspnet-ajax/grdupdatingvaluesusercontrolformtemplate.html
http://www.telerik.com/help/aspnet-ajax/grdretrieveoriginalvaluesforediteditem.html
http://www.telerik.com/help/aspnet-ajax/grdinsertupdatedeleteatdatabaselevel.html

http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/editmodes/defaultcs.aspx


Thanks,
SamJ


0
Mike
Top achievements
Rank 1
answered on 03 Sep 2009, 01:17 PM
[EDIT] The following code doesn't work, because it does only extract the old (original) values........

----------------------------------------------------------------------------------------
Thanks for your help, The solution I found works perfectly


GridEditableItem editedItem = e.Item as GridEditableItem; 
Dictionary<string, string> newValues = new Dictionary<string, string>(); 
e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);   

mike
----------------------------------------------------------------------------------------

0
Mike
Top achievements
Rank 1
answered on 03 Sep 2009, 05:30 PM
I've now spend some hours to try to extract the changed values in the UpdateCommand Event but I had no luck. I always get the old (original) values, example: http://www.pronux.ch/oldValues.jpg

I don't know what I'm doing wrong here.....can you please give me a tip or an advice.

thanks in advance






mike


0
Sebastian
Telerik team
answered on 04 Sep 2009, 07:18 AM
Hello Mike,

Can you please verify that you use advanced binding with NeedDataSource event handling or assign a data source control for the grid as shown in the demos pointed out from SamJ?  Also confirm that the viewstate of the grid/the page on which it resides is enabled.

Best 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
Mike
Top achievements
Rank 1
answered on 04 Sep 2009, 01:21 PM
I'm storing the data in SQL Server Compact 3.5. The only possible data binding I found was the following:

ASP.NET:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True"  
                    AllowPaging="True" AllowSorting="True" AutoGenerateDeleteColumn="True"  
                    AutoGenerateEditColumn="True" GridLines="None" Skin="Vista" OnUpdateCommand="RadGrid1_UpdateCommand"

Code behind:
var config = from c in DB.Config select c;                         
RadGrid1.DataSource = config; 
RadGrid1.DataBind(); 

Is this the problem ?
0
Sebastian
Telerik team
answered on 04 Sep 2009, 01:23 PM
Hello Mike,

Switch to advance binding with NeedDataSource event handling using the same code without the DataBind() call and let me know how it goes.

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
Mike
Top achievements
Rank 1
answered on 04 Sep 2009, 02:13 PM
Hi Sebastian,

I made the suggested changes and it works now. Thanks a lot for your help.

Last question: When an UpdateCommand Event occurs, I update the DB with the changed values, but after that, the grid still shows the old (original) values. Is it possible to refresh the Grid ?

mike




0
Sebastian
Telerik team
answered on 04 Sep 2009, 02:31 PM
Hi Mike,

If you implement upates/inserts for the grid instance using one the approaches  for data extraction presented below:

http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/editmodes/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/extractvalues/defaultcs.aspx
 
and verify that the underlying source is modified, the control should reflect the changes made.

Best,
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
Mike
Top achievements
Rank 1
answered on 05 Sep 2009, 01:05 AM
thanks for the help! I found out, that my LINQ-Objekt was not actual and I have to refresh it manually in the NeedDataSource Event Handler:

        protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
        { 
            var config = from c in BAF.DB.Config select c; 
            BAF.DB.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, config); 
            RadGrid1.DataSource = config; 
            RadGrid1.Columns[2].Visible = false;             
        } 

Unfortunately the last line of code (RadGrid1.Columns[2].Visible = false;") throw the following exception:
"Failed accessing GridColumn by index. Please verify that you have specified the structure of RadGrid correctly."

As you can see above, I use a LINQ Collection as DataSource. Is it in my case possible to hide a column on the grid (at runtime) ?


0
Vlad
Telerik team
answered on 07 Sep 2009, 05:41 AM
Hello Mike,

Can you verify using the debugger if you have any columns in RadGrid1.Columns? Generally all columns (declared + auto-generated)  can be found in RenderColumns.

Regards,
Vlad
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
Mike
Top achievements
Rank 1
answered on 07 Sep 2009, 02:19 PM

In the in the NeedDataSource Event Handler I have no columns in RadGrid1.Columns: http://www.pronux.ch/debugger.JPG

I will try to place the code (RadGrid1.Columns[2].Visible = false;) in another RadGrid Event Handler....i.e. on OnPreRender ?


0
Accepted
Sebastian
Telerik team
answered on 07 Sep 2009, 03:01 PM
Hi Mike,

The differences between the Columns/AutoGeneratedColumns/RenderColumns collection of the grid are explained in this section of the documentation:

http://www.telerik.com/help/aspnet-ajax/grdgettingfamiliarwithclientapi.html

Additionally, how to customize columns programmatically you can see from the bottom section of this help topic.

Best 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
Mike
Top achievements
Rank 1
answered on 07 Sep 2009, 04:59 PM

Thanks for your help. With the following code it works perfectly:

protected void RadGrid1_DataBound(object source, EventArgs e) 
      RadGrid1.MasterTableView.AutoGeneratedColumns[0].Display = false;    

mike
0
Kfir
Top achievements
Rank 1
answered on 11 Nov 2012, 04:46 PM
hey, I also got the same prob. with the updated values.
I use the "NeedDataSource" and I do not use DataBind and the values I get after using the "update" button are still the old ones.
what am I doing wrong? shouldn't I re-retrieve the data from my DB in "NeedDataSource"?
0
Shinu
Top achievements
Rank 2
answered on 12 Nov 2012, 04:48 AM
Hi,

You can access the new values in UpdateCommand as shown below.
C#:
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
{
    GridEditableItem editItem = e.Item as GridEditableItem;
    Hashtable newValues = new Hashtable();
    e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editItem);
    string id = newValues["UniqueName"].ToString();
}

Thanks,
Shinu.
0
Kfir
Top achievements
Rank 1
answered on 27 Jan 2013, 09:25 AM
forgot to thank you... so thanx very much :)
0
Prashant
Top achievements
Rank 1
answered on 26 Apr 2013, 11:21 AM
Hi,

I am facing th same problem when i try to update the grid using OnUpdateCommand command for an AutoGenerateColumns='' true'' type grid.
It gives me the old values I tried using the code

Hashtable newValues = new Hashtable();
e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editItem);

this also gives the old values.
0
Tsvetoslav
Telerik team
answered on 01 May 2013, 05:58 AM
Hi Prashant,

I could not reproduce the issue as evidenced by the attached sample. Please, specify how to modify it in order that the problem be replicated.

Greetings, Tsvetoslav
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
Vincent
Top achievements
Rank 1
answered on 16 Jan 2018, 06:35 PM

I have been searching for this solution in the demos and could not find this particular example. This is a valuable solution which will save other developers many hours of searching. Can this be incorporated into one of the demos?

0
Eyup
Telerik team
answered on 19 Jan 2018, 08:16 AM
Hello Vincent,

The ExtractValues method is used in the following corresponding live sample:
https://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/manual-crud-operations/defaultcs.aspx

Alternatively, you can also access the specific control in order to get its value during UpdateCommand event handler:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-controls-in-editinsert-mode

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
SamJ
Top achievements
Rank 1
Mike
Top achievements
Rank 1
Sebastian
Telerik team
Vlad
Telerik team
Kfir
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Prashant
Top achievements
Rank 1
Tsvetoslav
Telerik team
Vincent
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or