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

How to highlight last edited row when sorting is enabled to column that needs to be changed.

3 Answers 33 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 18 Sep 2012, 02:31 AM

Folks,

Using VS2010 with RadControls for ASP.NET AJAX Q2 2012 SP2. I am using below link (the 2nd Grid as a prototype).

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/commanditem/defaultcs.aspx

I would like to highlight last updated row when sorting is enabled. Below codes works (i.e. does highlight the last updated row in current page when sorting is not enabled prior to editing).

protected void RadGrid2_PreRender(object sender, EventArgs e)
        {
            if (rowindex > -1)
            {
 
                GridDataItem item = (GridDataItem)RadGrid2.Items[rowindex];
 
                item.Selected = true;
 
                rowindex = -1;
 
            }
        }
         
int rowindex = -1;
protected void RadGrid2_UpdateCommand(object sender, GridCommandEventArgs e)
        {
 
            GridEditFormItem editItem = (GridEditFormItem)e.Item;
 
            rowindex = editItem.ItemIndex;
        }

 

But lets see if sorting is enabled (i.e. in Contact Name) and if in edit form, I change the Contact Name from Ann Devon to Beann Devon, after update Beann Devon is not showing in current page ( I assume because sorting is enabled in column Contact Name). Please refer to attached.

Is there any way possible to highlight that updated row if sorting is enabled prior to edit? If not, how about disable sorting prior to edit, after update highlight the row and enable sorting or any other suggestions? My users may sort any column, change that column value and still would like to highlight that row after update.

Thanks for any help.

gc_0620

 

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 Sep 2012, 05:33 AM
Hi,

One suggestion is to Highlight the Updated row based on the 'DataKeyValue' rather than the row index. Here is the sample code snippet I tried.

C#:
protected void RadGrid2_PreRender(object sender, EventArgs e)
{
    foreach (GridDataItem ditem in RadGrid2.MasterTableView.Items)
    {
        string CurrentDatakey = ditem.OwnerTableView.DataKeyValues[ditem.ItemIndex]["DataKey"].ToString();
        if (UpdatedDataKey == CurrentDatakey)
        {
            ditem.Selected = true;
        }
    }
}
static string UpdatedDataKey = string.Empty;
protected void RadGrid2_UpdateCommand(object sender, GridCommandEventArgs e)
{
        
    GridEditFormItem editItem = (GridEditFormItem)e.Item;
    UpdatedDataKey = editItem.OwnerTableView.DataKeyValues[editItem.ItemIndex]["DataKey"].ToString();
}

Thanks,
Shinu.
0
gc_0620
Top achievements
Rank 1
answered on 19 Sep 2012, 01:20 PM
Sorry Shinu,

It did not work. If I change the Sorted column content during edit, after update that row is not highlighted. It works (does highlight) if the Grid is not sorted prior to edit.  My Grid has paging enabled.

Thanks

gc_0620
0
Pavlina
Telerik team
answered on 06 Nov 2012, 03:01 PM
Hi,

I suggest that you examine the approach suggested in the below article and see if it will work for you:
http://www.telerik.com/help/aspnet-ajax/grid-selected-row-at-all-times.html

Regards,
Pavlina
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.
Tags
Grid
Asked by
gc_0620
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
gc_0620
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or