Were here, were here

2 posts, 0 answers
  1. Phil
    Phil avatar
    273 posts
    Member since:
    Jul 2008

    Posted 30 Jun 2009 Link to this post

    Hi:
    I need some means to notify my parent page that the RadWindow has returned and the data has changed, so that I may reload the data.
    Any suggestions?
    Phil
    Horton ... were here ...
  2. Phil
    Phil avatar
    273 posts
    Member since:
    Jul 2008

    Posted 30 Jun 2009 Link to this post

    Answered my own:
    http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=grid
    w/ no code-behind, and no telerik session:
    <%@ Page Language="C#" %> 
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <script runat="server"
        protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridDataItem) 
            { 
                HyperLink editLink = (HyperLink)e.Item.FindControl("EditLink"); 
                editLink.Attributes["href"] = "#"; 
                int _id = (int)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["EmployeeID"]; 
                editLink.Attributes["onclick"] = String.Format("return ShowEditForm('{0}','{1}');", _id, e.Item.ItemIndex); 
            } 
        } 
        protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e) 
        { 
            if (e.Argument == "Rebind") 
            { 
                RadGrid1.MasterTableView.SortExpressions.Clear(); 
                RadGrid1.MasterTableView.GroupByExpressions.Clear(); 
                RadGrid1.Rebind(); 
            } 
            else if (e.Argument == "RebindAndNavigate") 
            { 
                RadGrid1.MasterTableView.SortExpressions.Clear(); 
                RadGrid1.MasterTableView.GroupByExpressions.Clear(); 
                RadGrid1RadGrid1.MasterTableView.CurrentPageIndex = RadGrid1.MasterTableView.PageCount - 1; 
                RadGrid1.Rebind(); 
            } 
        } 
    </script> 
    <html xmlns="http://www.w3.org/1999/xhtml"
    <head runat="server"
        <title></title
    </head> 
    <body> 
        <form id="form1" runat="server"
        <asp:ScriptManager ID="ScriptManager" runat="server" /> 
        <div> 
           <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"
                <script type="text/javascript"
                    function ShowEditForm(id, rowIndex) { 
                        var grid = $find("<%= RadGrid1.ClientID %>"); 
                        var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element(); 
                        grid.get_masterTableView().selectItem(rowControl, true); 
                        window.radopen("EditFormCS.aspx?EmployeeID=" + id, "UserListDialog"); 
                        return false; 
                    } 
                    function ShowInsertForm() { 
                        window.radopen("EditFormCS.aspx", "UserListDialog"); 
                        return false; 
                    } 
                    function refreshGrid(arg) { 
                        if (!arg) { 
                            $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind"); 
                        } 
                        else { 
                            $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("RebindAndNavigate"); 
                        } 
                    } 
                    function RowDblClick(sender, eventArgs) { 
                        window.radopen("EditFormCS.aspx?EmployeeID=" + eventArgs.getDataKeyValue("EmployeeID"), "UserListDialog"); 
                    } 
                </script> 
            </telerik:RadCodeBlock> 
                <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest"
                    <AjaxSettings> 
                        <telerik:AjaxSetting AjaxControlID="RadAjaxManager1"
                            <UpdatedControls> 
                                <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                            </UpdatedControls> 
                        </telerik:AjaxSetting> 
                        <telerik:AjaxSetting AjaxControlID="RadGrid1"
                            <UpdatedControls> 
                                <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                            </UpdatedControls> 
                        </telerik:AjaxSetting> 
                    </AjaxSettings> 
                </telerik:RadAjaxManager> 
                <asp:SqlDataSource ID="nwSqlDataSource" runat="server"  
                ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"  
                SelectCommand="SELECT [EmployeeID], [FirstName], [LastName], [Title] FROM [Employees]"
            </asp:SqlDataSource> 
                <telerik:RadGrid 
                    OnItemCreated="RadGrid1_ItemCreated" 
                    ID="RadGrid1" 
                    runat="server" 
                    AllowPaging="True" 
                    Width="97%" 
                    DataSourceID="nwSqlDataSource"
                    <PagerStyle Mode="NumericPages" /> 
                    <MasterTableView 
                        AutoGenerateColumns="False" 
                        DataKeyNames="EmployeeID" 
                        ClientDataKeyNames="EmployeeID" 
                        Width="100%" 
                        CommandItemDisplay="Top" 
                        PageSize="5"
                        <Columns> 
                            <telerik:GridBoundColumn 
                                DataField="EmployeeID" 
                                HeaderText="EmployeeID" 
                                ReadOnly="True" 
                                SortExpression="EmployeeID" 
                                UniqueName="EmployeeID"
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn 
                                DataField="FirstName" 
                                HeaderText="FirstName" 
                                SortExpression="FirstName" 
                                UniqueName="FirstName"
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn 
                                DataField="LastName" 
                                HeaderText="LastName" 
                                SortExpression="LastName" 
                                UniqueName="LastName"
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn 
                                DataField="Title" 
                                HeaderText="Title" 
                                SortExpression="Title" 
                                UniqueName="Title"
                            </telerik:GridBoundColumn> 
                            <telerik:GridTemplateColumn 
                                UniqueName="TemplateEditColumn"
                                <ItemTemplate> 
                                    <asp:HyperLink ID="EditLink" runat="server" Text="Edit"></asp:HyperLink> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                        </Columns> 
                        <CommandItemTemplate> 
                            <href="#" onclick="return ShowInsertForm();">Add New Record</a> 
                        </CommandItemTemplate> 
                    </MasterTableView> 
                    <ClientSettings> 
                        <Selecting AllowRowSelect="true" /> 
                        <ClientEvents OnRowDblClick="RowDblClick" /> 
                    </ClientSettings> 
                </telerik:RadGrid> 
                 
                <telerik:RadWindowManager ID="RadWindowManager1" runat="server"
                    <Windows> 
                        <telerik:RadWindow ID="UserListDialog" runat="server" Title="Editing record" Height="400px" 
                            Width="300px" Left="150px" ReloadOnShow="true" ShowContentDuringLoad="false" Modal="true" /> 
                    </Windows> 
                </telerik:RadWindowManager> 
            </div> 
        </form> 
    </body> 
    </html> 
     
    and the window program EditFormCS.aspx w/ no code-behind:
    <%@ Page Language="C#" %> 
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <script runat="server"
        protected override void OnInit(EventArgs e) 
        { 
            base.OnInit(e); 
            if (Request.QueryString["EmployeeID"] == null) 
            { 
                DetailsView1.DefaultMode = DetailsViewMode.Insert; 
            } 
            else 
            { 
                DetailsView1.DefaultMode = DetailsViewMode.Edit; 
            } 
            this.Page.Title = "Editing record"
        } 
        protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e) 
        { 
            if (e.CommandName == "Update") 
            { 
                ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind();", true); 
            } 
            else if (e.CommandName == "Insert") 
            { 
                ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind('navigateToInserted');", true); 
            } 
            else 
            { 
                ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CancelEdit();", true); 
            } 
        } 
    </script> 
    <html xmlns="http://www.w3.org/1999/xhtml"
    <head runat="server"
        <title></title
    </head> 
    <body> 
        <form id="form1" runat="server"
        <div> 
            <script type="text/javascript"
            function CloseAndRebind(args) 
            { 
                GetRadWindow().Close(); 
                GetRadWindow().BrowserWindow.refreshGrid(args); 
            } 
             
            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> 
            <asp:ScriptManager ID="ScriptManager2" runat="server" /> 
            <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" Skin="Vista" /> 
                <asp:DetailsView ID="DetailsView1"  
                    DataKeyNames="EmployeeID" runat="server" AutoGenerateRows="False" 
                    DataSourceID="nwSqlDataSource" Height="50px" Width="125px"  
                    OnItemCommand="DetailsView1_ItemCommand" 
                    BorderWidth="0px" CellPadding="0" CellSpacing="7" GridLines="None"
                <Fields> 
                    <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" /> 
                    <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" /> 
                    <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" /> 
                    <asp:CommandField ShowEditButton="True" ButtonType="Button" /> 
                    <asp:CommandField ShowInsertButton="True" ButtonType="Button" /> 
                </Fields> 
            </asp:DetailsView> 
                <asp:SqlDataSource ID="nwSqlDataSource" runat="server"  
                    ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"  
                    DeleteCommand="DELETE FROM [Employees] WHERE [EmployeeID] = @EmployeeID"  
                    InsertCommand="INSERT INTO [Employees] ([LastName], [FirstName], [Title]) VALUES (@LastName, @FirstName, @Title)"  
                    SelectCommand="SELECT [EmployeeID], [LastName], [FirstName], [Title] FROM [Employees] WHERE ([EmployeeID] = @EmployeeID)"  
                     
                UpdateCommand="UPDATE [Employees] SET [LastName] = @LastName, [FirstName] = @FirstName, [Title] = @Title WHERE [EmployeeID] = @EmployeeID"
                    <SelectParameters> 
                        <asp:QueryStringParameter Name="EmployeeID" QueryStringField="EmployeeId"  
                            Type="Int32" /> 
                    </SelectParameters> 
                    <DeleteParameters> 
                        <asp:Parameter Name="EmployeeID" Type="Int32" /> 
                    </DeleteParameters> 
                    <UpdateParameters> 
                        <asp:Parameter Name="LastName" Type="String" /> 
                        <asp:Parameter Name="FirstName" Type="String" /> 
                        <asp:Parameter Name="Title" Type="String" /> 
                        <asp:Parameter Name="EmployeeID" Type="Int32" /> 
                    </UpdateParameters> 
                    <InsertParameters> 
                        <asp:Parameter Name="LastName" Type="String" /> 
                        <asp:Parameter Name="FirstName" Type="String" /> 
                        <asp:Parameter Name="Title" Type="String" /> 
                    </InsertParameters> 
                </asp:SqlDataSource> 
            </div> 
        </form> 
    </body> 
    </html> 
     




Back to Top