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

Confirm Cancel in Detail Table. If Confirmed Cancel, Close Detail Table Edit Form (i.e. Rebind the Detail Table).

2 Answers 29 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 01 Oct 2014, 09:18 PM
Folks, using UI for ASP.NET AJAX Q2 2014 SP1 with VS 2010.

In My Radgrid, I have Cancel Confirm both for Parent and Child Grid. Cancel Confirm works well in Parent Grid. Not an issue there.

But in Child Grid,  Cancel Confirm does not work; edit form stays open. AllowAutomaticInserts="false" AllowAutomaticUpdates = "false" in Child Grid.

Below is my client side code.

function confirmCancelBackFnChild(arg) {
               // var grid = $telerik.findControl(document.body, "RadGrid2");
               var grid = $find("<%= RadGrid1.ClientID %>");
               if (arg)
               {
                   var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
                   var detailTable = grid.get_detailTables()[0];
                   var detailtableName = detailTable.get_name();
 
                   // alert(detailtableName);
                   document.getElementById('<%=HiddenField1.ClientID%>').value = "true";
 
                   // detailTable.fireCommand("CancelConfirmed", 0);
                   detailTable.fireCommand("CancelConfirmed", String.Empty);
 
               }
 
               else
               {
 
                   document.getElementById('<%=HiddenField1.ClientID%>').value = "false";
 
               }
 
               document.getElementById('<%=HiddenField1.ClientID%>').value = "false";
           }


Below is my Item command for the Command for the Child Grid.

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        RadGrid grid = (source as RadGrid);
         
        if (true && e.Item.OwnerTableView.Name == "DemographicsDependants") // Child Table
        {
            switch (e.CommandName)
            {
                case "Cancel":
                    int searchlocation = 0;
                    string[] retrievedLocations = (string[])Session["LocationData"];
                    Array.Sort(retrievedLocations);
 
                    string location = Session["SessionOtherInfoFacilityName"].ToString().Trim();
                    searchlocation = Array.BinarySearch(retrievedLocations, location);
 
                    //  if (HiddenField1.Value == "false" && searchlocation >= 0)
                    if (HiddenField1.Value == "false")
                    {
                        e.Canceled = true;
                        Session["savedIndex"] = e.Item.ItemIndex;
                        RadWindowManager1.RadConfirm("Continue with Cancel in Child Table? Warning, you will loose any unsaved work!!!", "confirmCancelBackFnChild", 350, 150, null, "Cancel Confirm");
                    }
                    break;
                case "CancelConfirmed":
                    foreach (GridEditableItem item in RadGrid1.MasterTableView.DetailTables[0].GetItems(GridItemType.EditFormItem))
                    {
                        if (item.IsInEditMode && item.ItemIndex == (int)Session["savedIndex"])
                        {
                            item.FireCommandEvent("Cancel", String.Empty);
                        }
                    }
                    // HiddenField1.Value = "false";
                      
                    break;
            }
        }
    }


Thanks for any Help.

gc_0620










2 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 06 Oct 2014, 11:12 AM
Hi,

I have examined the provided JavaScript and your code-behind for the server-side OnItemCommand event, but without the markup of your grid it would be difficult to guess what is your exact implementation.

Having that in mind, can you please provide the markup of your grid, so we can have a better idea of your exact implementation and test the same scenario locally.

I am looking forward to your reply.


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
gc_0620
Top achievements
Rank 1
answered on 07 Oct 2014, 01:28 PM
Hi Konstantin, please close the thread. I was able to resolve with below codes.

Thanks
gc_0620
function confirmCancelBackFnChild()
{
 
                return (confirm('Continue with Cancel? Warning, you will loose any unsaved work!!!'));
 }
                 
                 
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
 
        if (e.Item.OwnerTableView.Name == "Detail") // Child Table
        {
 
           if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
            {
              
                GridEditableItem editItem = (GridEditableItem)e.Item;
                ImageButton img = (ImageButton)editItem.FindControl("ImageButtonDetailCancelUpdateInsert");
 
                img.Attributes.Add("onclick", "return confirmCancelBackFnChild();");
            }
        }
  }
      
 <tr>
       <td align="right" colspan="6">
                                            
         <asp:ImageButton ID="ImageButtonDetailCancelUpdateInsert" ToolTip="Cancel" TabIndex="26"
                                               
        CommandName="Cancel" CausesValidation="false" runat="server" ImageUrl="~/Images/GridCancelEditInsert.gif" />
       </td>
  </tr>
Tags
Grid
Asked by
gc_0620
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
gc_0620
Top achievements
Rank 1
Share this question
or