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

Maintain current page when adding new record

1 Answer 100 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joe Loux
Top achievements
Rank 1
Joe Loux asked on 01 Aug 2008, 09:36 PM
In the RadGrid that we're currently using when you go to add a record it changes the page index to the last page. Is there any way to stay on the current page when doing an add?

Thanks

1 Answer, 1 is accepted

Sort by
0
Sean
Top achievements
Rank 2
answered on 01 Aug 2008, 09:48 PM
Hello Joe,

Try something like this:

protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.InitInsertCommandName)
{
  e.Canceled = true;
  Session[
"curPageIndex"] = e.Item.OwnerTableView.CurrentPageIndex;
  e.Item.OwnerTableView.InsertItem();

  e.Item.OwnerTableView.CurrentPageIndex =
int.Parse(Session["curPageIndex"]);
  e.Item.OwnerTableView.Rebind();
 }
 
else if (e.CommandName == RadGrid.CancelCommandName && e.Item.OwnerTableView.IsItemInserted)
 {
     e.Item.OwnerTableView.CurrentPageIndex =
int.Parse(Session["curPageIndex"]);
 }
}

It captures the CurrentpageIndex value before you execute the insert, then resets it after you are done.

Thanks!
Sean
Electronic Arts, Orlando FL
Tags
Grid
Asked by
Joe Loux
Top achievements
Rank 1
Answers by
Sean
Top achievements
Rank 2
Share this question
or