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

[Solved] adding row does not go to last page in hierarchical grid

3 Answers 130 Views
Grid
This is a migrated thread and some comments may be shown as answers.
TriZetto
Top achievements
Rank 1
TriZetto asked on 27 Jul 2009, 08:56 PM
Hello,
I am adding a row to a child grid in the OnInsertCommand event. This is working as expected. But I would like to move to the last page in the grid and select the row that was just inserted. I am doing the following, but I always remain on the first page of the child grid.
protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e) 
    string serverID = null
    string insertType = "master"
     
    GridEditFormItem gridEditFormItem = (GridEditFormItem)e.Item; 
 
    Hashtable ht = new Hashtable(); 
    gridEditFormItem.ExtractValues(ht); 
 
 
    if ("Systems".Equals(e.Item.OwnerTableView.Name)) 
    { 
        GridDataItem parentItem = (GridDataItem)e.Item.OwnerTableView.ParentItem; 
 
        serverID = parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["ServerID"].ToString(); 
        insertType = "detail"
    } 
     
    presenter.InsertRecord(serverID, ht, insertType); 
     
    XmlDataSource1.Save(); 
     
    //rebind to get the real number of pages (incase adding an item increased the page count 
    RadGrid1.Rebind(); 
    if ("Systems" != e.Item.OwnerTableView.Name) 
    { 
        //set to last page 
        RadGrid1.CurrentPageIndex = RadGrid1.PageCount - 1; 
 
        //after changing page, need to rebind 
        RadGrid1.Rebind(); 
    } 
    else 
    { 
        GridTableView table = e.Item.OwnerTableView; 
         
        //set to last page 
        table.CurrentPageIndex = table.PageCount - 1; 
 
        //after changing page, need to rebind 
        table.Rebind(); 
         
    } 

In this example, "Systems" is the name of the Detail grid view.
also, is there away to do this without doing so many rebind calls?
Thanks
-marcos


3 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 28 Jul 2009, 10:49 AM
Hi Marcos,

How to select the last inserted row in RadGrid for ASP.NET AJAX you can see from the project in the code library entry linked below:

http://www.telerik.com/community/code-library/aspnet-ajax/grid/select-last-inserted-row.aspx

How to control on which page the insertion form will be displayed is presented by the configurator on this online demo:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/commanditem/defaultcs.aspx

By default you should be directed to the last page where the newly added row is visible.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
TriZetto
Top achievements
Rank 1
answered on 31 Jul 2009, 03:31 PM
Hello,
The default behavior and the example you provided both work fine for the master table. But I am still not having any luck with the detail table. For some reason, setting the CurrentPageIndex in the e.Item.OwnerTableView and rebinding does not work when this is a detail table.
I am using version Q2 2009
0
Sebastian
Telerik team
answered on 05 Aug 2009, 02:19 PM
Hi Marcos,

If you set the InsertItemPageIndexAction for the respective detail table to ShowItemOnLastPage, you do not need to change the page index for that child table manually since the last page will be displayed after the insert operation is processed (as shown in the online example). Then you merely need to select the last inserted record in the grid as done in the code library entry.

Kind regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
TriZetto
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
TriZetto
Top achievements
Rank 1
Share this question
or