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

Finding the SelectedIndexes

4 Answers 148 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kit
Top achievements
Rank 1
Kit asked on 06 Dec 2010, 02:21 PM
Hello again.

I have a nested grid scenario, and on updating a record in the child grid, I need to ReBind() the parent grid.

e.Canceled = true;
grdProfileIntakes.Rebind();

However, doing this collapses the grid.  I need it to refresh and then expand the appropriate nodes to where it was.  Going through the documentation, I think I have two possible solutions.  First is using Grid.SelectedIndexes.Add(indexOfSelectedParentTableRow, indexOfParentTable), second is using Grid.MasterTableView.Items[indexOfSelectedItem].Expanded = true.

Both methods need the index of the selected item, specifically the index of the parent  of the selected child item.  How can I get this value?

TIA

kitster

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 07 Dec 2010, 06:23 AM
Hello Kitster,

You can save the index of parent item after performing the operation on child item. Please take a look at the following sample code which illustrates the same.
C#:
int index=-1;
 
protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
{
    . . . . . . .
    RadGrid1.Rebind();
    index = e.Item.OwnerTableView.ParentItem.ItemIndex; // saving index of parent item
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    if (index > -1)
    {
        RadGrid1.MasterTableView.Items[index].Expanded = true;
        index = -1;
    }
}

Thanks,
Princy.
0
Kit
Top achievements
Rank 1
answered on 07 Dec 2010, 09:07 AM
Princy, you're a saviour, again.  For the record, I didn't need to user the PreRender event, all within the update command:

grdProfileIntakes.MasterTableView.ClearChildEditItems(); //Close the InPlace edit form
e.Canceled = true; //Need to cancel the operation so that the ReBind can work
grdProfileIntakes.Rebind(); //Requery the grid so parent row shows updates from child row
int parentIndex = e.Item.OwnerTableView.ParentItem.ItemIndex; //Index of parent item
grdProfileIntakes.MasterTableView.Items[parentIndex].Expanded = true; //Set the parent item to expanded

Now, one further question, naturally.  Am I doing this the right way?  The parent record has a calculated value, based on its child records.  Do I need to ReBind the entire grid to force the recalculation, or can I requery an individual record in the parent grid?

Thanks again Princy, I haven't got anywhere near enough hair to carry on tearing it out on things like this...

kitster
0
Tsvetina
Telerik team
answered on 10 Dec 2010, 10:55 AM
Hi Kit,

This is correct, when you want to refresh a value in the master table based on values in the detail tables, you need to rebind the whole RadGrid control.

Best wishes,
Tsvetina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Kit
Top achievements
Rank 1
answered on 10 Dec 2010, 10:58 AM
Many thanks Tsvetina, good to know I'm on the right track

kitster
Tags
Grid
Asked by
Kit
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Kit
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or