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

Expand Grid Row Details On Edit?

6 Answers 54 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 13 Dec 2012, 02:11 AM
How do I expand the current Row's detail table when I edit the row?

I've followed the code here and used the EditCommand event, but it doesn't work. Should I use the client-side object model instead?

6 Answers, 1 is accepted

Sort by
0
Peter
Top achievements
Rank 1
answered on 13 Dec 2012, 02:22 AM
I've tried using client-side... but this doesn't work either...

<telerik:RadScriptBlock runat="server" ID="rsbScripts">
    </telerik:RadScriptBlock>

protected void rgUnits_EditCommand(object sender, GridCommandEventArgs e)
       {
           e.Item.Expanded = true;
 
           LiteralControl lc = (LiteralControl)rsbScripts.Controls[0];
           lc.Text = string.Format(JSExpandRow, rgUnits.ClientID, e.Item.ItemIndex);

private const string JSExpandRow = "<script type=\"text/javascript\"> " +
                                            "var grid = $find(\"{0}\"); " +
                                            "master = grid.get_masterTableView(); " +
                                            "master.expandItem({1}); " +
                                        "</script>";
 
0
Shinu
Top achievements
Rank 1
answered on 13 Dec 2012, 04:21 AM
Hi,

Try the following code to achieve your scenario.
C#:
protected void RadGrid2_ItemCommand(object sender, GridCommandEventArgs e)
 if (e.CommandName == RadGrid.EditCommandName && e.Item.OwnerTableView.Name == "DetailTable1")
 {
    GridTableView childtable = (GridTableView)e.Item.OwnerTableView;
    foreach (GridDataItem childItem in childtable.Items)
    {
      childItem.Expanded = true;
    }
 }
}

Thanks,
Shinu.
0
Peter
Top achievements
Rank 1
answered on 13 Dec 2012, 04:47 AM
Thanks - but unfortunately this didn't work... it seems when the Edit User Control loads, it un-expands (or never expands).

<EditFormSettings UserControlName="~/Controls/UnitItemReplace.ascx" EditFormType="WebUserControl">

0
Peter
Top achievements
Rank 1
answered on 13 Dec 2012, 04:50 AM
A similar thing happens with the client-side - it expands, but once the UserControl loads, it unexpands.

<ClientSettings>
                        <ClientEvents OnCommand="ExpandRow" />
                    </ClientSettings>

function ExpandRow(sender, eventArgs) {               
                var grid = sender;
                var master = grid.get_masterTableView();
                master.expandItem(eventArgs.get_commandArgument());
                return true;
            }
0
Accepted
Eyup
Telerik team
answered on 17 Dec 2012, 11:35 AM
Hello Peter,

Please try the following approach:
int itemIndex = -1;
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.EditCommandName)
    {
        itemIndex = e.Item.ItemIndex;
    }
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    if (itemIndex >= 0)
    {
        RadGrid1.MasterTableView.Items[itemIndex].FireCommandEvent("ExpandCollapse", String.Empty);
    }
}

I hope this will prove helpful. Please give it a try and let me know about the result.

All the best,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Peter
Top achievements
Rank 1
answered on 18 Dec 2012, 12:16 AM
That works thanks!
Tags
Grid
Asked by
Peter
Top achievements
Rank 1
Answers by
Peter
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or