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

Select Inserted/Updated row after performing command

12 Answers 748 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ronnie
Top achievements
Rank 1
Ronnie asked on 24 Sep 2010, 09:21 PM
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

12 Answers, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 29 Sep 2010, 12:11 PM
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
0
Miguel
Top achievements
Rank 1
answered on 09 Dec 2010, 04:32 AM
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
0
Princy
Top achievements
Rank 2
answered on 09 Dec 2010, 06:56 AM
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.
0
Miguel
Top achievements
Rank 1
answered on 10 Dec 2010, 01:13 AM
Perfect!!!. Thanks again Princy.
0
pikopatel
Top achievements
Rank 1
answered on 03 Jun 2014, 04:18 PM
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.
0
Princy
Top achievements
Rank 2
answered on 04 Jun 2014, 07:29 AM
Hi,

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

Thanks,
Princy
0
pikopatel
Top achievements
Rank 1
answered on 04 Jun 2014, 01:20 PM
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?
0
Princy
Top achievements
Rank 2
answered on 09 Jun 2014, 03:55 AM
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
0
LaurentDuveau
Top achievements
Rank 1
answered on 19 Mar 2015, 03:29 PM
Hi,
This link is not working anymore, where can I find it ?
Thanks.
0
Eyup
Telerik team
answered on 24 Mar 2015, 12:53 PM
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.

 
0
Keletso
Top achievements
Rank 1
answered on 12 Dec 2016, 09:02 AM
How can i select an item using the Id of updated item 
0
Eyup
Telerik team
answered on 15 Dec 2016, 07:13 AM
Hello Keletso,

You will first need to access the item. Then, you can set its Selected property to true on server-side. Alternatively, you can use one of the following methods on client-side:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/client-side-programming/gridtableview-object/methods/selectitem
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/client-side-programming/griddataitem-object/properties/set_selected()

I hope this will prove helpful.

Regards,
Eyup
Telerik by Progress
Try our brand new, jQuery-free Angular 2 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
Ronnie
Top achievements
Rank 1
Answers by
Mira
Telerik team
Miguel
Top achievements
Rank 1
Princy
Top achievements
Rank 2
pikopatel
Top achievements
Rank 1
LaurentDuveau
Top achievements
Rank 1
Eyup
Telerik team
Keletso
Top achievements
Rank 1
Share this question
or