S.Mohamed sami S.Mohamed sami - 1 month ago 33
ASP.NET (C#) Question

Master-Detail Gridview Devexpress

I have a Master Grid and Detail Grid, Detail Grid allows me to UPDATE and DELETE but it is not refreshing. If I Update twice or Delete twice it is deleting or else when I expand the Master Grid the Updated data are shown in the Detail Grid. I am using CallBackPanel here. How can I refresh the Detail Grid?

<dx:ASPxCallbackPanel runat="server" ID="CallbackPanel"
ClientInstanceName="CallbackPanel" OnCallback="CallbackPanel_Callback">

<PanelCollection>

<dx:PanelContent ID="PanelContent3" runat="server">

<dx:ASPxGridView ID="grdMasterBuilding"
ClientInstanceName="grdMasterBuilding"
runat="server" KeyFieldName="BuildingId" AutoGenerateColumns="False">

<Columns>
<dx:GridViewDataTextColumn
FieldName="Name" Caption="Building Name"/>

<dx:GridViewDataTextColumn
FieldName="Description" Caption="Building Description">
</Columns>

<Templates>
<DetailRow>

<dx:ASPxGridView ID="grdDetailBuilding"
ClientInstanceName="grdDetailBuilding" runat="server"
KeyFieldName="FloorId" AutoGenerateColumns="False"

<Columns>
<dx:GridViewDataTextColumn
FieldName="FloorCode" Caption="Floor Code">
<dx:GridViewDataTextColumn>

<dx:GridViewDataTextColumn
FieldName="FloorLength" Caption="Floor Width" />
</dx:GridViewDataTextColumn>

<dx:GridViewDataTextColumn
FieldName="FloorHeight" Caption="Floor" />
</dx:GridViewDataTextColumn>

<dx:GridViewDataComboBoxColumn
FieldName="FloorType" Caption="Floor Type" />
</dx:GridViewDataComboBoxColumn>

<dx:GridViewDataComboBoxColumn
FieldName="DeliveryOption" VisibleIndex="9"
Caption="Delivery Option" />
</dx:GridViewDataComboBoxColumn>

<dx:GridViewDataTextColumn
FieldName="NumbersOfUnits" Caption="No Of Units"
</dx:GridViewDataTextColumn>

<dx:GridViewDataTextColumn
FieldName="SquareFeet" Caption="Square Feet"
</dx:GridViewDataTextColumn>
</Columns>

</dx:ASPxGridView>

</DetailRow>
</Templates>

<SettingsDetail ShowDetailRow="true" />

</dx:ASPxGridView>
</dx:PanelContent>
</PanelCollection>



Answer

See this example: https://www.devexpress.com/Support/Center/Example/Details/E3578 .

Basically the idea is that you need to process the EndCallback client side event of the detail grid and update master grid using ClientInstanceName: grdMasterBuilding.Refresh() .

So you have to add the following line to the detail grid markup before the <Columns> element:

<ClientSideEvents EndCallback="OnEndCallback" BeginCallback="OnBeginCallback"/>

then add these JS OnBeginCallback and OnEndCallback methods like in the mentioned example only that in OnEndCallback you will use your master grid ClientInstanceName to refresh it.

function OnEndCallback(s, e) {
   if ((command == "ADDNEWROW" || command == "UPDATEEDIT") && !s.isError) {
      grdMasterBuilding.Refresh();
   }
}

If you don't need to update master grid upon child edit/delete, try refreshing only the child grid in the same way, by using grdDetailBuilding.Refresh() . Note, the example saves the action command name during OnBeginCallback and then checks if the command was ADDNEWROW or UPDATEEDIT. You may need to add the check for the delete action. I'm not sure if UPDATEEDIT will be called for row deletion, maybe there is a separate command for that. You can know that by using browser developer tools and stopping at breakpoint in the OnBeginCallback.

HTH

Comments