how to refresh radgrid2 within radgrid 1 using radwindow

4 posts, 1 answers
  1. TippCityTom
    TippCityTom avatar
    14 posts
    Member since:
    Sep 2008

    Posted 24 Jul 2009 Link to this post

    I have a radwindow that pops up to update data residing record in radgrid2, but when data is successfully updated in database via radwinow and window is closed, the data in radgrid2 is not updated on the screen.  

    <

     

    telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">

     

     

    <AjaxSettings>

     

     

    <telerik:AjaxSetting AjaxControlID="btnDelete">

     

     

    <UpdatedControls>

     

     

    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />

     

     

    </UpdatedControls>

     

     

    </telerik:AjaxSetting>

     

     

    <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">

     

     

    <UpdatedControls>

     

     

    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />

     

     

    <telerik:AjaxUpdatedControl ControlID="RadGrid2" />

     

     

    </UpdatedControls>

     

     

    </telerik:AjaxSetting>

     

     

     

    <telerik:AjaxSetting AjaxControlID="RadGrid1">

     

     

    <UpdatedControls>

     

     

    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />

     

     

    <telerik:AjaxUpdatedControl ControlID="RadGrid2" />

     

     

    </UpdatedControls>

     

     

    </telerik:AjaxSetting>

     

     

     

    <telerik:AjaxSetting AjaxControlID="RadGrid2">

     

     

    <UpdatedControls>

     

     

    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />

     

     

    <telerik:AjaxUpdatedControl ControlID="RadGrid2" />

     

     

    </UpdatedControls>

     

     

    </telerik:AjaxSetting>

     

     

    </AjaxSettings>

     

     

    </telerik:RadAjaxManager>



     

    <

     

    telerik:RadWindow

     

     

    ID="PostWindow"

     

     

    runat="server"

     

     

    Modal="true"

     

     

    BackColor="Gray"

     

     

    Behavior="None"

     

     

     

     

     

    InitialBehaviors="Pin"

     

     

     

     

     

    ShowContentDuringLoad="false"

     

     

     

     

     

    Title="Add/Edit Post (Fields in BOLD are required!)"

     

     

    Width="650"

     

     

     

     

     

    Height="470"

     

     

     

     

     

    ReloadOnShow="true"

     

     

     

     

     

    DestroyOnClose="true"

     

     

     

     

     

    KeepInScreenBounds="true"

     

     

     

     

     

    BorderStyle="None"

     

     

    OnClientClose="refreshGrid1()"

     

     

    >

     

     

     

     

     

    </telerik:RadWindow>


    1) when user clicks on close button it passes arg value called 'editPost'

     

    <

     

    telerik:RadScriptBlock runat="server">

     

     

     

     

     

    <script type="text/javascript">

     

     

     

     

     

    function refreshGrid1(arg)

     

    {

    $find(

    "<%= RadAjaxManager1.ClientID %>").ajaxRequest(arg);

     

     

     

     

     

     

     

    }

     

    </script>

     

     

     

     

     

    </telerik:RadScriptBlock>

    2) RadAjaxManager1_AjaxRequest is then fired and the following code is performed but nothing happens

     

    if

     

    (isPost)

     

    {

    radGrid = radGrid2;

    RadGrid1.MasterTableView.Rebind();

    radGrid.MasterTableView.Rebind();

  2. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 29 Jul 2009 Link to this post

    Hi Thomas,

    Your code seems to be fine. Make sure that you successfully update your RadGrid data source inside your window before updating. Attached is a sample web site with the same approach working properly. Check it out.

    Regards,
    Veli
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. TippCityTom
    TippCityTom avatar
    14 posts
    Member since:
    Sep 2008

    Posted 12 Aug 2009 Link to this post

    Thanks for the code, great example when using ONE grid.  How do you use it when you are trying to upgrade RadGrid2 (see title) that is nested within RadGrid1, my code behind does NOT even see RadGrid2  because RadGrid2 is nested as shown below:


    RadGrid1

    <NestedViewTemplate>
         <fieldset style="padding: 10px;">
                        <legend style="padding: 5px;"><b>Posts for: </b><%# Eval("NOMENCLATURE")%> 
                            <asp:Label ID="Label2" runat="server" Font-Bold="true" Font-Italic="true" Text='<%# Eval("ITEM") %>' Visible="false"></asp:Label>
                            <asp:Label ID="Label1" runat="server" Font-Bold="true" Font-Italic="true" Text='<%# Eval("ID") %>' Visible="false"></asp:Label>
                        </legend>
                        
                        <asp:SqlDataSource ID="RadGrid2Source" runat="server"
                            ConnectionString="<%$ ConnectionStrings:dbConnectionString %>"
                            ProviderName="<%$ AppSettings:providerName %>"
                            SelectCommand="SELECT * FROM V_POSTS WHERE TOPICID = :ID ORDER BY ID">
                            <SelectParameters>
                                <asp:ControlParameter ControlID="Label1" Name="ID" PropertyName="" Type="Int32" />
                            </SelectParameters>
                        </asp:SqlDataSource>
              
                        <telerik:RadGrid ID="RadGrid2" runat="server"
                            OnNeedDataSource="RadGrid2_NeedDataSource"
                            AllowMultiRowSelection="False"
                            AllowPaging="True"
                            AllowSorting="True"
                            AutoGenerateColumns="False"
                            GridLines="None"
                            HeaderStyle-Wrap="false"
                            PageSize="10"
                            ShowStatusBar="true"
                            Skin="Web20"
                            Width="600px"
                            >
                            <PagerStyle Mode="Slider" />
                           
                            <MasterTableView AllowMultiColumnSorting="True" AlternatingItemStyle-BackColor="AliceBlue" DataSourceID="RadGrid2Source">
                                <Columns>
                                    <telerik:GridBoundColumn DataField="ID" HeaderButtonType="TextButton" HeaderText="Post ID" Visible="false">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="TOPICID" HeaderButtonType="TextButton" HeaderText="Topic ID" UniqueName="TOPICID" Visible="false">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="USERID" HeaderButtonType="TextButton" HeaderText="User ID" UniqueName="USERID" Visible="false">
                                    </telerik:GridBoundColumn>
                                   
                                    <telerik:GridTemplateColumn UniqueName="Post" HeaderText="" ReadOnly="true" Display="true" ItemStyle-VerticalAlign="Top" HeaderStyle-Width="600px" >
                                        <ItemTemplate>
                                            <%# RadGrid2_Post(Convert.ToInt32(Eval("ID")), Convert.ToInt32(Eval("USERID")), Eval("CREATEDON").ToString(), Eval("USERNAME").ToString(), Eval("APPROVED").ToString(), Eval("BODY").ToString())%>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                </Columns>
                               
                            </MasterTableView>
                            <ClientSettings>
                                <Selecting AllowRowSelect="true" />
                            </ClientSettings>
                           
                        </telerik:RadGrid>
                    </fieldset>
                </NestedViewTemplate>
  5. Answer
    Veli
    Admin
    Veli avatar
    2002 posts

    Posted 13 Aug 2009 Link to this post

    Hello Thomas,

    void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e) 
        if (e.Argument == "Refresh"
        { 
            RadGrid1.MasterTableView.Rebind(); 
        } 

    The above piece of code is what you need anyway. Particularly, no matter how many levels of nested tables you have, RadGrid will rebind them all. I think this should work for your case too. If, however, you want to rebind only the nested RadGrid, you need to find it:

    void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e) 
        if (e.Argument == "Refresh"
        { 
            (RadGrid1.MasterTableView.Items[0].ChildItem.FindControl("RadGrid2"as RadGrid).Rebind(); 
        } 

    In the above code, you need to replace 0 with the index of the parent data item that you know has its nested grid updated.

    Regards,
    Veli
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top