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

Hierarchical Grid Refresh

3 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 29 Jun 2012, 06:06 PM
Hi,
I have a 3 level hierarchical grid.It is populated programatically (i.e. through 'DetailTableDataBind')

Each row in the middle-level grid has a hyperlink, which if pressed causes a dialog to be displayed (through RadWindowManager).

When the dialog is closed (by clicking 'Save'), the dialog closed, and calls a 'refreshGrid' function in the parent.

The 'refreshGrid' then does a 'ajaxRequest("RebindAndNavigate")'.

All pretty standard stuff, except it doesn't seem to refresh the contents of the 3rd level grid.

Am I missing something- does the rebind refresh all displayed 'programmatic-populated' children tables?

Cheers,
Steve


3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 30 Jun 2012, 10:37 AM
Hello Steve,

TelerikPage.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TelerikPage.aspx.cs" Inherits="TelerikPage" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function openpopup(id, Parentid) {
                var oWnd = radopen("TelerikPopup.aspx?id=" + id + "&Parentid=" + Parentid, "RadWindow1");
                oWnd.show();
                return false;
            }
 
            function OnClientClose(oWnd, args) {
 
                var arg = args.get_argument();
                if (arg) {
                    var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");
                    ajaxManager.ajaxRequest("RebindChild" +","+ arg);
                }
            }
 
        </script>
    </telerik:RadCodeBlock>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server" OnClientClose="OnClientClose">
            <Windows>
                <telerik:RadWindow ID="RadWindow1" runat="server" OnClientClose="OnClientClose">
                </telerik:RadWindow>
            </Windows>
        </telerik:RadWindowManager>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
            onajaxrequest="RadAjaxManager1_AjaxRequest">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
            OnDetailTableDataBind="RadGrid1_DetailTableDataBind" OnItemDataBound="RadGrid1_ItemDataBound">
            <MasterTableView DataKeyNames="ID" HierarchyLoadMode="Client">
                <Columns>
                    <telerik:GridBoundColumn HeaderText="ID" DataField="ID" UniqueName="ID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn HeaderText="Name" DataField="Name" UniqueName="Name">
                    </telerik:GridBoundColumn>
                </Columns>
                <DetailTables>
                    <telerik:GridTableView Name="Child">
                        <Columns>
                            <telerik:GridTemplateColumn>
                                <ItemTemplate>
                                    <asp:LinkButton ID="lnk1" runat="server">open popup</asp:LinkButton>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn HeaderText="ID" DataField="ID" UniqueName="ID">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn HeaderText="Name" DataField="Name" UniqueName="Name">
                            </telerik:GridBoundColumn>
                        </Columns>
                    </telerik:GridTableView>
                </DetailTables>
            </MasterTableView>
        </telerik:RadGrid>
    </div>
    </form>
</body>
</html>

TelerikPage.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
 
public partial class TelerikPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
 
    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        dynamic data = new[] {
                new { ID = 1, Name ="Name1"},
                new { ID = 2, Name = "Name2"},
                new { ID = 3, Name = "Name3"}
            };
        RadGrid1.DataSource = data;
    }
 
    protected void RadGrid1_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
    {
        string str =  e.DetailTableView.ParentItem.GetDataKeyValue("ID").ToString();
 
        string strtemp = string.Empty;
 
        if (Session["CheckIsUpdate"] != null)
        {
            strtemp = Session["CheckIsUpdate"].ToString();
        }
 
        dynamic data = new[] {
                new { ID = 11, Name ="Name11"+strtemp},
                new { ID = 22, Name = "Name22"+strtemp},
                new { ID = 33, Name = "Name33"+strtemp}
            };
        e.DetailTableView.DataSource = data;
    }
 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Child")
        {
            GridDataItem item = e.Item as GridDataItem;
            LinkButton lnk1 = item.FindControl("lnk1") as LinkButton;
            lnk1.Attributes.Add("onclick", "return openpopup('" + item.GetDataKeyValue("ID") + "','" + item.OwnerTableView.ParentItem.GetDataKeyValue("ID") + "'  );");
        }
    }
    protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
    {
        string[] str = e.Argument.Split(',');
        if(str.Length == 2)
        {
            if (str[0].ToString() == "RebindChild")
            {
                foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
                
                    if (item.HasChildItems && item.GetDataKeyValue("ID").ToString() == str[1].ToString())
                    {
                        item.ChildItem.NestedTableViews[0].Rebind();
                    }
                }
            }
        }
             
    }
}

TelerikPopup.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TelerikPopup.aspx.cs" Inherits="TelerikPopup" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function GetRadWindow() {
                var oWindow = null;
                if (window.radWindow) oWindow = window.radWindow;
                else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
                return oWindow;
            }
 
            function returnToParent() {
                var oWnd = GetRadWindow();
                var parentId = "<%= MyProperty %>";
                oWnd.close(parentId);
            }
        </script>
    </telerik:RadCodeBlock>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Save" OnClientClick="returnToParent(); return false;" />
    </div>
    </form>
</body>
</html>

TelerikPopup.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class TelerikPopup : System.Web.UI.Page
{
    public string MyProperty
    {
        get
        {
            if (Request.QueryString["Parentid"] != null)
            {
                return Request.QueryString["Parentid"].ToString();
            }
            else
            {
                return string.Empty;
            }
        }
    }
 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["id"] != null)
        {
            Response.Write(Request.QueryString["id"].ToString());
 
            Session["CheckIsUpdate"] =DateTime.Now;
        }
    }
}


Thanks,
Jayesh Goyani
0
Steve
Top achievements
Rank 1
answered on 02 Jul 2012, 02:58 PM
Jayesh, Hi,
Thanks for that.

How do I use RebindChild for the 3rd level in the hierarchy?
For example, the grid has

+ Level 1
   + Level 2
         Level 3

A button at level 2 calls a dialog to be displayed.
When the dialog is closed, an extra record/row is added to Level 3. What I need is for the level 3 'child grid' to be refreshed.

Hope this makes sense!

Cheers,
Steve

0
Jayesh Goyani
Top achievements
Rank 2
answered on 03 Jul 2012, 06:18 AM
Hello Steve,

TelerikPopup.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TelerikPopup.aspx.cs" Inherits="TelerikPopup" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
    <style type="text/css">
        .chklstMaxwidth
        {
            height:100px;
            overflow:scroll;
        }
    </style>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function GetRadWindow() {
                var oWindow = null;
                if (window.radWindow) oWindow = window.radWindow;
                else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
                return oWindow;
            }
 
            function returnToParent() {
                var oWnd = GetRadWindow();
                var parentId = "<%= MyPropertyFirstParent %>" + "," + "<%= MyPropertySecondParent %>";
                oWnd.close(parentId);
            }
        </script>
    </telerik:RadCodeBlock>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Save" OnClientClick="returnToParent(); return false;" />
    </div>
    </form>
</body>
</html>

TelerikPopup.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class TelerikPopup : System.Web.UI.Page
{
    public string MyPropertyFirstParent
    {
        get
        {
            if (Request.QueryString["Parentid"] != null)
            {
                return Request.QueryString["Parentid"].ToString();
            }
            else
            {
                return string.Empty;
            }
        }
    }
 
    public string MyPropertySecondParent
    {
        get
        {
            if (Request.QueryString["id"] != null)
            {
                return Request.QueryString["id"].ToString();
            }
            else
            {
                return string.Empty;
            }
        }
    }
 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["id"] != null)
        {
            Response.Write(Request.QueryString["id"].ToString());
 
            Session["CheckIsUpdate"] =DateTime.Now;
        }
    }
}


TelerikPage.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TelerikPage.aspx.cs" Inherits="TelerikPage" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function openpopup(id, Parentid) {
                var oWnd = radopen("TelerikPopup.aspx?id=" + id + "&Parentid=" + Parentid, "RadWindow1");
                oWnd.show();
                return false;
            }
 
            function OnClientClose(oWnd, args) {
 
                var arg = args.get_argument();
                if (arg) {
                    var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");
                    ajaxManager.ajaxRequest("RebindChild" + "," + arg);
                }
            }
 
        </script>
    </telerik:RadCodeBlock>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server" OnClientClose="OnClientClose">
            <Windows>
                <telerik:RadWindow ID="RadWindow1" runat="server" OnClientClose="OnClientClose">
                </telerik:RadWindow>
            </Windows>
        </telerik:RadWindowManager>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
            OnDetailTableDataBind="RadGrid1_DetailTableDataBind" OnItemDataBound="RadGrid1_ItemDataBound">
            <MasterTableView DataKeyNames="ID" HierarchyLoadMode="Client">
                <Columns>
                    <telerik:GridBoundColumn HeaderText="ID" DataField="ID" UniqueName="ID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn HeaderText="Name" DataField="Name" UniqueName="Name">
                    </telerik:GridBoundColumn>
                </Columns>
                <DetailTables>
                    <telerik:GridTableView Name="Child1" DataKeyNames="ID">
                        <Columns>
                            <telerik:GridTemplateColumn>
                                <ItemTemplate>
                                    <asp:LinkButton ID="lnk1" runat="server">open popup</asp:LinkButton>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn HeaderText="ID" DataField="ID" UniqueName="ID">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn HeaderText="Name" DataField="Name" UniqueName="Name">
                            </telerik:GridBoundColumn>
                        </Columns>
                        <DetailTables>
                            <telerik:GridTableView Name="Child2">
                                <Columns>
                                    <telerik:GridBoundColumn HeaderText="ID" DataField="ID" UniqueName="ID">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn HeaderText="Name" DataField="Name" UniqueName="Name">
                                    </telerik:GridBoundColumn>
                                </Columns>
                            </telerik:GridTableView>
                        </DetailTables>
                    </telerik:GridTableView>
                </DetailTables>
            </MasterTableView>
        </telerik:RadGrid>
        <br />
    </div>
    </form>
</body>
</html>

TelerikPage.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
 
public partial class TelerikPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
 
    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        dynamic data = new[] {
                new { ID = 1, Name ="Name1"},
                new { ID = 2, Name = "Name2"},
                new { ID = 3, Name = "Name3"}
            };
        RadGrid1.DataSource = data;
    }
 
    protected void RadGrid1_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
    {
        if (e.DetailTableView.Name == "Child1")
        {
            dynamic data = new[] {
                new { ID = 11, Name ="Name11"},
                new { ID = 22, Name = "Name22"},
                new { ID = 33, Name = "Name33"}
            };
            e.DetailTableView.DataSource = data;
        }
        else
        {
 
            string str = e.DetailTableView.ParentItem.GetDataKeyValue("ID").ToString();
 
            string strtemp = string.Empty;
 
            if (Session["CheckIsUpdate"] != null)
            {
                strtemp = Session["CheckIsUpdate"].ToString();
            }
 
            dynamic data = new[] {
                new { ID = 11, Name ="Name111"+strtemp},
                new { ID = 22, Name = "Name222"+strtemp},
                new { ID = 33, Name = "Name333"+strtemp}
            };
            e.DetailTableView.DataSource = data;
        }
    }
 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Child1")
        {
            GridDataItem item = e.Item as GridDataItem;
            LinkButton lnk1 = item.FindControl("lnk1") as LinkButton;
            lnk1.Attributes.Add("onclick", "return openpopup('" + item.GetDataKeyValue("ID") + "','" + item.OwnerTableView.ParentItem.GetDataKeyValue("ID") + "'  );");
        }
    }
    protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
    {
        string[] str = e.Argument.Split(',');
        if (str.Length == 3)
        {
            if (str[0].ToString() == "RebindChild")
            {
                foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
                {
                    if (item.HasChildItems && item.GetDataKeyValue("ID").ToString() == str[1].ToString())
                    {
                        foreach (GridDataItem itemc1 in item.ChildItem.NestedTableViews[0].Items)
                        {
                            if (itemc1.GetDataKeyValue("ID").ToString() == str[2].ToString())
                            {
                                itemc1.ChildItem.NestedTableViews[0].Rebind();
                            }
                        }
                    }
                }
            }
        }
 
    }
}

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Steve
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Steve
Top achievements
Rank 1
Share this question
or