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

[Solved] Retain edited row position in RadGrid..

1 Answer 147 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Milan Gurung
Top achievements
Rank 1
Milan Gurung asked on 07 Jul 2009, 08:50 AM
Hi,

I would be grateful if anyone can hint me how can I achieve the following behaviour with RadGrid.

"Grid contains multiiple rows per page. User can edit any row at a time. Generally when the row is edited and updated, the change is passed to the database and updated. Now I am looking for a way so that user is taken back to the same row that was just edited rather than to the first row when grid rebinds"

Many thanks.
Milan G

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 07 Jul 2009, 10:55 AM
Hello Milan,

A possible approach for your scenario is to get an updated text on the update button click event using the column UniqueName property and after updating search for the updated text in the grid in the PreRender event of the grid. You can understand better by referring to the code below:
aspx:
<telerik:GridBoundColumn DataField="ProductName" HeaderText="Product Name" UniqueName="ProductName" ></telerik:GridBoundColumn> 

cs:
    string strtxt;  
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)  
    {  
        if (e.CommandName == "Update")  
        {  
            GridEditableItem editItem = (GridEditableItem)e.Item;  
            strtxt = (editItem["ProductName"].Controls[0] as TextBox).Text; //get the updated text for a column   
               // update query    
        }    
    }  
 
    protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
        { 
            if (item["ProductName"].Text == strtxt) //search for the update text 
            { 
                item.Selected = true//optional 
                item.Focus(); //focus the row  
            }             
        }      
    } 

Thanks
Princy.
Tags
Grid
Asked by
Milan Gurung
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or