Setting focus on page after insert

2 posts, 0 answers
  1. Alexandru
    Alexandru avatar
    5 posts
    Member since:
    Jun 2015

    Posted 08 Jul 2015 Link to this post

    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.

  2. Eyup
    Admin
    Eyup avatar
    3797 posts

    Posted 13 Jul 2015 Link to this post

    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
Back to Top