Get values in UpdateCommand Event

19 posts, 1 answers
  1. Mike
    Mike avatar
    26 posts
    Member since:
    Jun 2008

    Posted 02 Sep 2009 Link to this post

    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




  2. SamJ
    SamJ avatar
    101 posts
    Member since:
    Jul 2008

    Posted 03 Sep 2009 Link to this post

    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


  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mike
    Mike avatar
    26 posts
    Member since:
    Jun 2008

    Posted 03 Sep 2009 Link to this post

    [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
    ----------------------------------------------------------------------------------------

  5. Mike
    Mike avatar
    26 posts
    Member since:
    Jun 2008

    Posted 03 Sep 2009 Link to this post

    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


  6. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 04 Sep 2009 Link to this post

    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.
  7. Mike
    Mike avatar
    26 posts
    Member since:
    Jun 2008

    Posted 04 Sep 2009 Link to this post

    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 ?
  8. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 04 Sep 2009 Link to this post

    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.
  9. Mike
    Mike avatar
    26 posts
    Member since:
    Jun 2008

    Posted 04 Sep 2009 Link to this post

    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




  10. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 04 Sep 2009 Link to this post

    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.
  11. Mike
    Mike avatar
    26 posts
    Member since:
    Jun 2008

    Posted 04 Sep 2009 Link to this post

    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) ?


  12. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 07 Sep 2009 Link to this post

    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.
  13. Mike
    Mike avatar
    26 posts
    Member since:
    Jun 2008

    Posted 07 Sep 2009 Link to this post


    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 ?


  14. Answer
    Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 07 Sep 2009 Link to this post

    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.
  15. Mike
    Mike avatar
    26 posts
    Member since:
    Jun 2008

    Posted 07 Sep 2009 Link to this post


    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
  16. Kfir
    Kfir avatar
    5 posts
    Member since:
    Nov 2012

    Posted 11 Nov 2012 Link to this post

    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"?
  17. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 11 Nov 2012 Link to this post

    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.
  18. Kfir
    Kfir avatar
    5 posts
    Member since:
    Nov 2012

    Posted 27 Jan 2013 Link to this post

    forgot to thank you... so thanx very much :)
  19. Prashant
    Prashant avatar
    3 posts
    Member since:
    Feb 2012

    Posted 26 Apr 2013 Link to this post

    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.
  20. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 01 May 2013 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017