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

Open child DetailGridView in insert mode from parent row command

1 Answer 143 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 1
Ian asked on 28 Jun 2012, 11:34 PM
how can I have the child grid open in insert mode? I tried a number of different things but it keeps saying that it can't find my linq datasource control when I rebind at the detail level or the master level. I need to be able to expand a row with command button and have the child detail grid loaded in insert mode all in one click.

When the rebind is called here at any level it yields this from ajax postback.
69|error|500|Cannot find DataSourceControl with ID 'ldsVendorRatingQualifications'|

Thanks,

protected void gridRatings_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandName == "AddNewChildRating") {
                GridDataItem parentRow = e.Item as GridDataItem;
                GridTableView parentGridView = parentRow.GetClosestParentControlByType<GridTableView>();
                RadGrid parentGrid = parentGridView.GetClosestParentControlByType<RadGrid>();
   
                parentRow.Expanded = true;
                //parentGridView.HierarchyDefaultExpanded = true;
                //parentGridView.DetailTables[0].InsertItem();
                parentGridView.DetailTables[0].IsItemInserted = true;
                parentGridView.DetailTables[0].Rebind();
    }
}

1 Answer, 1 is accepted

Sort by
0
Ian
Top achievements
Rank 1
answered on 29 Jun 2012, 09:48 PM
I figured this out, hopefully this will help someone else. The solution is to cast the command handler e.Item to a GridDataItem; which gives you access to the NestedTableViews - the key to the puzzle. This is the detail view that is actually connected with data unlike DetailTables. Once you set theIsItemInserted on that and rebind it all works like charm. This allows you to expand a section and put the child section in insert mode all in one shot. Here is the completed code below.

...
    <DetailTables>
        <telerik:GridTableView>
        ...
        <Columns>
            <ItemTemplate>
                <asp:LinkButton ID="addChildVendorRating" runat="server" CommandName="AddNewChildRating" CausesValidation="false" CssClass="normal-link" CommandArgument='<%# Eval("VendorM2MEntityToQualID")%>'>[Add Rating]</asp:LinkButton>
            </ItemTemplate>
        </Columns>
        <DetailTables>
            <!-- I Need this to be be expanded and in insert mode when addChildVendorRating command link is clicked -->
            <telerik:GridTableView>
        </<DetailTables>


protected void gridRatings_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        if (e.CommandName == "AddNewChildRating") {
                    GridDataItem parentRow = e.Item as GridDataItem;
                    GridTableView parentGridView = parentRow.GetClosestParentControlByType<GridTableView>();
 
                    if (parentGridView != null)
                    {
                        var targetGridView = ((GridDataItem)e.Item).ChildItem.NestedTableViews[0];
                        if (targetGridView != null)
                        {
                            parentRow.Expanded = true;
                            targetGridView.IsItemInserted = true;
                            targetGridView.Rebind();
                        }
                    }
 
}
Tags
Grid
Asked by
Ian
Top achievements
Rank 1
Answers by
Ian
Top achievements
Rank 1
Share this question
or