Rebind RadGrid MasterTableView & DetailTableView From DetailTableView

0 Answers 59 Views
Grid
Jeff
Top achievements
Rank 1
Jeff asked on 21 Sep 2021, 12:56 PM

Hello, 

I have the following scenario. I have an InPlace Edit within a cell in a DetailTableView. The source of the DetailTableView is a list from a DataKey ("Instances"/InstanceList) of the MasterTableView DataSource. When the InPlace edit completes w/ an UpdateCommand, I need to update the "Instances" value so the DetailTableView can be rebound w/ the fresh data. I am attempting to do that via Rebinding the whole Grid, but the DetailTableView throws an exception, because for some reason it is attempting to bind the RadGrid's DataSource (FormSelection), instead of it's own DataSource (InstanceList).

When I just run the UpdateCommand, the DetailTableView rebinds w/o the new data, likely because the "Instances" value is not getting rebound. If I try to rebind the RadGrid to get the new value, that is when the exception gets thrown.

Here is the MasterTable header in ASCX

	<telerik:RadGrid ID="rdgElectronicCCR" runat="server"
		AutoGenerateColumns="false"
		OnNeedDataSource="rdgElectronicCCR_NeedDataSource" 
		OnDetailTableDataBind="rdgElectronicCCR_DetailTableDataBind"
		OnItemCommand="rdgElectronicCCR_ItemCommand"
		OnItemDataBound="rdgElectronicCCR_ItemDataBound"
		OnUpdateCommand="instanceView_UpdateCommand"
		OnItemCreated="instanceView_ItemCreated"
		OnPreRender="rdgElectronicCCR_PreRender">
		<MasterTableView Name="MainView"
			AutoGenerateColumns="false"
			Width="100%" 
			RetainExpandStateOnRebind="true"
			DataKeyNames="GeneratedFormTemplateId,ShortName,Description,Instances,Instances.OpenInstanceCount,Instances.ClosedInstanceCount">
			<Columns>


DetailTable "InstanceView" in ASCX

<DetailTables>
				<telerik:GridTableView Name="InstanceView" 
					Width="90%"
					HorizontalAlign="Right"
					EditMode="InPlace"
					DataKeyNames="FormInstanceToken,IsComplete,CorrectionInProgress,PimsUserId,GeneratedFormInstanceId,WorkItems,Title">
					<Columns>
						<telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandInitiator">
							<HeaderStyle Width="50px" Wrap="false" />
                            <ItemStyle Width="50px" Wrap="false" />
						</telerik:GridEditCommandColumn>
						<telerik:GridButtonColumn UniqueName="Delete" ButtonType="ImageButton" CommandName="Delete" ConfirmText="Are you sure you want to delete this instance? This cannot be undone.">
							<HeaderStyle Width="1%" Wrap="false" />
							<ItemStyle Width="1%" Wrap="false" />
						</telerik:GridButtonColumn>
						<telerik:GridTemplateColumn UniqueName="Title" DataField="Title" HeaderText="Friendly Name">
							<ItemTemplate>
								<asp:Label runat="server" ID="lblTitle" Text='<%# Eval("Title") %>' ToolTip='<%# Eval("FormInstanceToken") %>'></asp:Label>
							</ItemTemplate>
							<EditItemTemplate>
								<telerik:RadTextBox runat="server" ID="rtbEditTitle" Text='<%# Eval("Title") %>' SkinID="RadTextBoxRequired"></telerik:RadTextBox>
							</EditItemTemplate>
							<HeaderStyle Width="1%" Wrap="false" />
							<ItemStyle Width="1%" Wrap="false" />
						</telerik:GridTemplateColumn>

 

DataSource for RadGrid and the DetailInstanceView in Code Behind

    

protected void rdgElectronicCCR_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { RadGrid rdg = (RadGrid)sender; if (!e.IsFromDetailTable) { var selections = new TemplateSelectionModel().GetLiveData(ctx, (int)EngineeringDataId); rdg.DataSource = selections.OrderBy(x => x.ShortName); }

}

 

protected void rdgElectronicCCR_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e) { RadGrid rdg = (RadGrid)sender; GridDataItem parentItem = (GridDataItem)e.DetailTableView.ParentItem; switch (e.DetailTableView.Name) { case"InstanceView": { InstanceList instances = (InstanceList)parentItem.GetDataKeyValue("Instances"); var orderedInstances = instances.OrderBy(x => x.IsComplete).ThenByDescending(x => x.ModifyDate).ToList(); e.DetailTableView.DataSource = orderedInstances; break; } } }


UpdateCommand in Code Behind

   

    protected void instanceView_UpdateCommand(object sender, GridCommandEventArgs e)
    {
        var item = (GridDataItem)e.Item;

        if (item.OwnerTableView.Name == "InstanceView")
        {
            var formInstanceToken = item.GetDataKeyValue("FormInstanceToken").ToString();

            var title = (RadTextBox) item.FindControl("rtbEditTitle");

            var newTitle = title.Text;

            var instanceManager = new GeneratedFormInstanceCreationManager(ctx);
            var existingInstanceSack = instanceManager.GetExistingInstance(Guid.Parse(formInstanceToken));
            var sack = existingInstanceSack.sack;

            sack.Title = newTitle;
            instanceManager.UpdateGeneratedFormInstanceSackTitle(sack);
            instanceManager.InvalidateCaches();

            //rdgElectronicCCR.Rebind();
        }
    }

 

Thanks for any help!

-Jeff

Attila Antal
Telerik team
commented on 23 Sep 2021, 05:16 PM

Hi Jeff,

Could you submit a formal support ticket and share an Isolated version of the sample that we can run and test? We are curious about the structure/model of the data you are binding to the Grid. That would help us find the culprit.

Once we find the solution, we could share the answer in this forum post as well and make it available to the community.

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Jeff
Top achievements
Rank 1
Share this question
or