Select Inserted/Updated row after performing command

11 posts, 0 answers
  1. Ronnie
    Ronnie avatar
    29 posts
    Member since:
    Oct 2008

    Posted 24 Sep 2010 Link to this post

    Hello,

    I have a grid and the Insert/Update/Delete events are handled in the 'ItemCommand' event.
    I'm now trying to get the dataItem row that was updated/inserted so that I can select it and then change it's BackColor.

    Here is what I have now in the ItemCommand  Event:
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
       if ((e.CommandName == RadGrid.PerformInsertCommandName) || (e.CommandName == RadGrid.UpdateCommandName))
       {
          GridEditableItem saveableItem = (GridEditableItem)e.Item;
          SaveItems(saveableItem, e.Item.OwnerTableView.IsItemInserted);
       }
    }

    I trying to do something like:  saveableItem.Selected = true;
    but this way won't work because it's the editableItem vs the dataItem.

    So my questions:
    - Is this the right event to handle this?  If not, what event should I call to handle this (from ItemCommand if possible)?
    - How do I 'get' the inserted/updated item, so that I can 'do something' (Select, change BackColor, add Border, etc. after the action)?

    Thank you in advance,
    Ronnie
  2. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 29 Sep 2010 Link to this post

    Hello Ronnie,

    Please try using the approach from the Select Last Inserted Row in the RadGrid with both Paging and Sorting enabled code library in order to implement the desired functionality.

    I hope this helps.

    Sincerely yours,
    Mira
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Miguel
    Miguel avatar
    25 posts
    Member since:
    Dec 2010

    Posted 08 Dec 2010 Link to this post

    Hello,

    The link given above is broken..

    Could you please help me how to select (highlight) the entire row that I just Edited/Inserted?

    Thanks!
    Miguel
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 09 Dec 2010 Link to this post

    Hello Miguel,

    Here is the link which shows how to select last inserted row.
    Select Last Inserted Row in the RadGrid with both Paging and Sorting enabled.

    And try the following code snippet to select the last updated row.

    C#:
    int rowindex = -1;
     protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
     {
         GridEditFormItem editItem = (GridEditFormItem)e.Item;
         rowindex = editItem.ItemIndex;
     }
     protected void RadGrid1_PreRender(object sender, EventArgs e)
     {
         if (rowindex > -1)
         {
             GridDataItem item = (GridDataItem)RadGrid1.Items[rowindex];
             item.Selected = true;
             rowindex = -1;
         }
     }

    Thanks,
    Princy.
  6. Miguel
    Miguel avatar
    25 posts
    Member since:
    Dec 2010

    Posted 09 Dec 2010 Link to this post

    Perfect!!!. Thanks again Princy.
  7. pikopatel
    pikopatel avatar
    2 posts
    Member since:
    Jun 2014

    Posted 03 Jun 2014 in reply to Princy Link to this post

    The link is broken - please provide correct link.  Looking for to select Last Inserted Row in the Select Last Inserted Row in the RadGrid with both Paging and Sorting enabled.
  8. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Jun 2014 in reply to pikopatel Link to this post

    Hi,

    Please take a look at the following article:
    http://www.telerik.com/support/code-library/select-last-inserted-row

    Thanks,
    Princy
  9. pikopatel
    pikopatel avatar
    2 posts
    Member since:
    Jun 2014

    Posted 04 Jun 2014 in reply to Princy Link to this post

    I have paging and sorting enable on my grid - Also, We are using Radwindow popup for Add/update. 

    We wanted to highlight Add/Update row to parent window after child window is close.  What can we use?
  10. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Jun 2014 in reply to pikopatel Link to this post

    Hi,

    You can attach CommandName to the edit button and access the index in the ItemCommand event and set the row selected. In case of add new record, it will be added to the end of the page, you can access it and set it selected.

    C#:
    protected void SampleGrid_ItemCommand(object sender, GridCommandEventArgs e)
    {
         //Edit
        if (e.CommandName == "EditRow")
        {
            GridDataItem dataItem = (GridDataItem)e.Item;
            int index = dataItem.ItemIndex;
            dataItem.Selected = true;
        }
          //Add new button in CommandItemTemplate
        if (e.CommandName == "AddNew")
        {
            GridCommandItem cmdItem = (GridCommandItem)e.Item;
            int count = SampleGrid.Items.Count;     
           //Set the last row selected
            SampleGrid.MasterTableView.Items[count - 1].Selected = true;
        }
    }

    Thanks,
    Princy
  11. LaurentDuveau
    LaurentDuveau avatar
    2 posts
    Member since:
    Jan 2007

    Posted 19 Mar 2015 in reply to Mira Link to this post

    Hi,
    This link is not working anymore, where can I find it ?
    Thanks.
  12. Eyup
    Admin
    Eyup avatar
    3015 posts

    Posted 24 Mar 2015 Link to this post

    Hi Laurent,

    This requirement may be somewhat tricky. You will need to find a way to determine the page and the position of the newly inserted record. You can also do that by removing paging temporarily to get the item, however, it requires 2 consequent rebinds, which is not performance friendly. I suggest that you access the database position of the new item using some server-side insert operation event handler depending on your datasource type. Then, you can make some calculations to determine on which page the newly inserted item is located on and go to that page. For instance, if you are using SQL, you can use the approach demonstrated in the attached web site.

    Hope this helps.


    Regards,
    Eyup
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017