I am using the Telerik RadGrid to display and edit Hierarchical data. As strange as this may sound - one of the requirements is to have a child detail grid open in insert mode when a link in the parent row is clicked. This requires two things. The expansion of the child grid, and getting this grid loaded in insert mode.
This is what I've tried so far using the recommendations from Telerik documentation; However this doesn't work and throws an exception when rebind is called saying that the child detail grid can't find its linqDataSourceControl; however this control does exist while this code below is executing (I checked).
What is the solution to open a child DetailGridView in insert mode from parent row command button?
Markup:
...
<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>
Code:
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();
}
}