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

Help me stop RadGrid going to last page on Insert & keep dropdownlist data

2 Answers 527 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 07 Jun 2012, 09:37 PM
I am using a radgrid populated by a standard object datasource with a matching data entity. The grid populates fine and everything is operating fine except for when the Add New Record button is clicked the grid loses its current page and goes to the last page of the grid.

I found a nifty way to stop that from happening along with preventing an edit and insert from occuring at the same time see code 1. This code block is firing on ItemCommand Insert Command.

The problem is when I call e.Canceled it completely messes up my ItemDataBound function that is populating a drop down list used to pick a value on insert. How can I do both, keep the drop down list populating appropriately and keep my paging where it started when the AddNewRecord was clicked? I am open to a solution that doesn't use code block 1 as i think it may over complicate it but I need some help on how to tackle the problem. Any ideas?

Code 1
switch (e.CommandName.ToUpper()) {
    case "INITINSERT":
        grid.MasterTableView.ClearEditItems();
        //Ensure the grid doesn't jump to the last page
        e.Canceled = true;
        int pageIndex = e.Item.OwnerTableView.CurrentPageIndex;
        e.Item.OwnerTableView.InsertItem();
        e.Item.OwnerTableView.CurrentPageIndex = pageIndex;
        e.Item.OwnerTableView.Rebind();
        return;
    case "EDIT":
        e.Item.OwnerTableView.IsItemInserted = false;
        return;

2 Answers, 1 is accepted

Sort by
0
Mike
Top achievements
Rank 1
answered on 07 Jun 2012, 09:51 PM
Murphy strikes again! Found the solution 2 seconds after posting.

For those interested I had to change the line:

e.Item.OwnerTableView.InsertItem();

to 

    e.Item.OwnerTableView.IsItemInserted = True;


solution found here by Mr. Yavor: http://www.telerik.com/community/forums/aspnet/grid/insert-jumps-auto-to-last-row.aspx

Thanks all!
1
Greg
Top achievements
Rank 2
answered on 03 Sep 2014, 05:03 PM
Just in case someone comes across this solution... I found a more recent post:
<telerik:RadGrid ID="RadGrid1" runat="server">
    <MasterTableView InsertItemPageIndexAction="ShowItemOnCurrentPage">
    </MasterTableView>
</telerik:RadGrid>

SMc
Top achievements
Rank 2
Iron
Veteran
Iron
commented on 29 Apr 2021, 04:09 PM

Thank you for this. It is nice to find an answer on my first search link!
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Mike
Top achievements
Rank 1
Greg
Top achievements
Rank 2
Share this question
or