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

Setting focus on page after insert

1 Answer 44 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alexandru
Top achievements
Rank 1
Alexandru asked on 08 Jul 2015, 02:37 PM

I have the following Radgrid control with AllowPaging = true. The Items in the Radgrid are sorted in decreasing order after the date in the second column. After I insert a row, I want the focus to be set on the page where the item was inserted. I have tried the following code in the Insert_Command event:

<telerik:RadGrid ID="rgCondica"
            runat="server"
            AllowPaging="true"
            AllowCustomPaging="true"
            AllowSorting="True"
            AutoGenerateColumns="False"
            Skin="Windows7"
            OnItemCommand="rgCondica_ItemCommand"
            OnItemDataBound="rgCondica_ItemDataBound"
            OnInsertCommand="rgCondica_InsertCommand"
            OnUpdateCommand="rgCondica_UpdateCommand"
            OnDeleteCommand="rgCondica_DeleteCommand"
            OnNeedDataSource="rgCondica_NeedDataSource"
            CellSpacing="0"
            CssClass="c1grid"
            GridLines="None"
            PageSize="5" PagerStyle-ShowPagerText="False"
            PagerStyle-AlwaysVisible="true" MasterTableView-NoMasterRecordsText="Nu exista inregistrari" PagerStyle-FirstPageToolTip="Prima pagina"
            PagerStyle-LastPageToolTip="Ultima pagina" PagerStyle-PageSizeLabelText="Nr. inregistrari:" PagerStyle-PrevPagesToolTip="Paginile anterioare"
            PagerStyle-PrevPageToolTip="Pagina anterioara" PagerStyle-NextPagesToolTip="Paginile urmatoare" PagerStyle-NextPageToolTip="Pagina anterioara">
            </telerik:RadGrid​>
protected void rgCondica_InsertCommand(object sender,GridCommandEventArgs e){
GridDataItem item = rgCondica.MasterTableView.FindItemByKeyValue("IdCondica", c.IdCondica);
 rgCondica.CurrentPageIndex = item.RowIndex;
 rgCondica.Rebind();}

but it remains on the last page.

 

Any help is appreciated. Thank you.

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 13 Jul 2015, 10:22 AM
Hello Alexandru,

This requirement may be somewhat tricky. You will need to find a way to determine the page and the position of the given record from the query string. Using the unique DataKeyValue of the item you can access the database position of the record by initiating some server-side query operation depending on your datasource type. Then, you can make some calculations to determine on which page the record is located on and go to that page using the CurrentPageIndex property. For instance, if you are using SQL, you can use an approach similar to the demonstrated implementation in the attached web site.

Hope this helps.

Regards,
Eyup
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Alexandru
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or