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

How to update RadGrid in Radwindow

0 Answers 70 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Yazan
Top achievements
Rank 1
Yazan asked on 20 Feb 2017, 06:19 PM

Hi

I have the following:

 

(Global.Master) => MasterPage

           (LoginValidationLayer.Master)  => Nasted Master Page (To check login sessions...) from the above Master "Global.Master" 

                      (CarsAndMachines.aspx)   => Web form With Master Page from the Above Master "LoginValidationLayer.Master" 

                              this form contents :  
                                          RadScriptManager (RadScriptManager1)
                                          RadCodeBlock (RadCodeBlock1)
                                          RadAjaxManager (RadAjaxManager1)
                                          RadAjaxLoadingPanel (RadAjaxLoadingPanel1)
                                          RadWindowManager (RadWindowManager1)
                                          Panel (MainPanel)

The RadCodeBlock declared as following:
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">
                function ShowOpenJobForm(machineId, rowIndex, companyId) {
                    var grid = $find("<%= CarsAndMachinesGrid.ClientID %>");
                        var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element();
                        grid.get_masterTableView().selectItem(rowControl, true);
 
                        window.radopen("EditOpenJobForm_csharp.aspx?MachineId=" + machineId + "&CompanyId=" + companyId, "OpenJobDialog");
                        return false;
                    }
            </script>
        </telerik:RadCodeBlock>

the RadAjaxManager declared as following :

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
    <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="MainPanel">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="MainPanel" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
    </telerik:RadAjaxManager>
to ajaxfy the updates and show progress when updating grid.

the RadWindowManager declared as following:

    <telerik:RadWindowManager RenderMode="Lightweight" ID="RadWindowManager1" runat="server" EnableShadow="true">
    </telerik:RadWindowManager>


the Panel contains RadGrid 
Inside this Web form I have RadGrid that set to show RadWindow when I click on one of it's columns (OpenJobsColumn) it is a GridTemplateColumn that has HyperLink that has OpenJobLink Id (it is an ItemTemplate)

I have set the link of the HyperLink control in the ItemCreated event as following :

                HyperLink openJobLink = (HyperLink)e.Item.FindControl("OpenJobLink");
                if (openJobLink != null)
                {
                    openJobLink .Attributes["href"] = "javascript:void(0);";
                    openJobLink .Attributes["onclick"] = String.Format("return ShowOpenJobForm('{0}','{1}','{2}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"], e.Item.ItemIndex, Request.QueryString["CompanyId"]);
                }


now when I click on the HyperLink (OpenJobLink) it shows the RadWindow and everything is great until here

inside the RadWindow I'm showing a Web Form which contains: (EditOpenJobForm_csharp.aspx)

                                          RadScriptManager (RadScriptManager1)
                                          RadCodeBlock (RadCodeBlock1)
                                          RadAjaxManager (RadAjaxManager1)
                                          RadAjaxLoadingPanel (RadAjaxLoadingPanel1)
                                          RadWindowManager (RadWindowManager1)
                                          RadGrid (PartsGrid)
                                          ScriptManager(ScriptManager1)

 

the RadCodeBlock declared as following:

    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function ShowEditForm(id, rowIndex) {
                var grid = $find("<%= PartsGrid.ClientID %>");
                    var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element();
                    grid.get_masterTableView().selectItem(rowControl, true); 
                    window.radopen("EditOpenJobPartsForm_csharp.aspx?InvoiceId=" + id, "OpenJobPartsDialog");
                    return false;
                }
                function ShowInsertForm() {
                    window.radopen("EditOpenJobPartsForm_csharp.aspx?InvoiceId", "OpenJobPartsDialog");
                    return false;

                }
                function refreshGrid(arg) {
                    if (!arg) {
                        $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");
                    }
                    else {
                        $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("RebindAndNavigate");
                    }
                }
                function RowDblClick(sender, eventArgs) {
                    window.radopen("EditOpenJobPartsForm_csharp.aspx?InvoiceId=" + eventArgs.getDataKeyValue("InvoiceId"), "OpenJobPartsDialog");
                    return false;
                }
        </script>
    </telerik:RadCodeBlock>

the RadAjaxManager declared as following:

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
<AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="PartsGrid">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="PartsGrid" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
</telerik:RadAjaxManager>

in the ASPX I declared a script as following :

           <script type="text/javascript">

            function CloseAndRebind(args)
            {
                GetRadWindow().BrowserWindow.refreshGrid(args);
                GetRadWindow().close();
            }
 
            function GetRadWindow()
            {
                var oWindow = null;
                if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
                else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz as well)
 
                return oWindow;
            }
 
            function CancelEdit()
            {
                GetRadWindow().close();
            }
        </script>

The RadGrid (PartsGrid) has a column for edit (GridTemplateColumn) declared as following:

                                <telerik:GridTemplateColumn UniqueName="TemplateEditColumn">
                                    <ItemTemplate>
                                        <asp:HyperLink ID="EditLink" runat="server" Text="Edit"></asp:HyperLink>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>


and I set to show RadWindow to edit the selected record in the grid (PartsGrid) using ItemCreated event as following :

            if (e.Item is GridDataItem)
            {
                HyperLink editLink = (HyperLink)e.Item.FindControl("EditLink");
                editLink.Attributes["href"] = "javascript:void(0);";
                editLink.Attributes["onclick"] = String.Format("return ShowEditForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"], e.Item.ItemIndex);
            }

and the AjaxRequest of RadAjaxManager is declared in code behind as following:

        protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            if (e.Argument == "Rebind")
            {
                PartsGrid.MasterTableView.SortExpressions.Clear();
                PartsGrid.MasterTableView.GroupByExpressions.Clear();
                PartsGrid.Rebind();
            }
            else if (e.Argument == "RebindAndNavigate")
            {
                PartsGrid.MasterTableView.SortExpressions.Clear();
                PartsGrid.MasterTableView.GroupByExpressions.Clear();
                PartsGrid.MasterTableView.CurrentPageIndex = PartsGrid.MasterTableView.PageCount - 1;
                PartsGrid.Rebind();
            }
        }

now when I click on Edit a RadWindow appears over the previous RadWindow and shows a DetailsView to update the selected record of PartsGrid

When I click on update this RadWindow it doesn't update the RadGrid while in database I can see the record updated and the updates doesn't appear until I do a full refresh (close the Previous RadWindow and open it again)

although in detailsview I set the following:

 

        protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e)
        {
            if (e.CommandName == "Update")
            {
                ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebindA();", true);
            }
            else if (e.CommandName == "Insert")
            {
                ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebindA('navigateToInserted');", true);
            }
            else
            {
                ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CancelEdit();", true);
            }
        }

and it contains : 

        <script type="text/javascript">
            function CloseAndRebindA(args)
            {
                var oWnd = GetRadWindowA(); 
                var DialogB = oWnd.get_windowManager().getWindowByName("OpenJobDialog");
                DialogB.refreshGrid(args);
                window.close();
            }
 
            function alerto()
            {
                alert("this is a test");
            }

            function GetRadWindowA()
            {
                var oWindow = null;
                if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
                else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz as well)
 
                return oWindow;
            }
 
            function CancelEdit()
            {
                GetRadWindow().close();
            }
        </script>
        <asp:ScriptManager ID="ScriptManager3" runat="server" />

 

I need to update a RadGrid located in a RadWindow using a DetailsView in another RadWindw and apply the updates to appear directly 

I'm not sure if it is about ajax or I don't know

Thank you.

No answers yet. Maybe you can help?

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