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

SelfHierarchy in grid not working

1 Answer 23 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sharmili Rao
Top achievements
Rank 1
Sharmili Rao asked on 07 Jul 2010, 06:15 PM
<telerik:RadAjaxManager ID="RadAjaxMgr" runat="server" > 
                <AjaxSettings> 
                    <telerik:AjaxSetting AjaxControlID="RadGrid1">  
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting> 
                </AjaxSettings> 
            </telerik:RadAjaxManager> 
        <telerik:RadGrid ID="RadGrid1" AutoGenerateColumns="true" ShowHeader="true" runat="server"    
            Width="97%" GridLines="None" OnNeedDataSource="RadGrid1_NeedDataSource" OnDetailTableDataBind="RadGrid1_DetailTableDataBind">    
            <MasterTableView Name="Master" DataKeyNames="Id, Parent_id" GridLines="Both" PageSize="15"    
                HierarchyDefaultExpanded="true" HierarchyLoadMode=ServerOnDemand>    
                <SelfHierarchySettings KeyName="id" ParentKeyName="Parent_id" />    
            </MasterTableView>    
        </telerik:RadGrid>  

Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource  
        If Not e.IsFromDetailTable Then  
            RadGrid1.DataSource = GetDataTable(" SELECT ID, P_ID FROM MY_TB order by ordnl_pos ")  
        End If  
End Sub  
 
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
        If Not IsPostBack Then  
            RadGrid1.MasterTableView.FilterExpression = "P_ID IS NULL" 
        End If  
End Sub 

When the Page loads it displays only the parent rows. The parent rows have the expand/collapse column but no child rows.
If I take out the filter on Page_Load it returns ALL rows but there are at the same level (no hierarchy)
Any suggestions?
Thanks.


1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 12 Jul 2010, 02:40 PM
Hello Sharmili Rao,

I have tested the sample bellow and it worked as expected on my side. Please give it a try and let me know how it goes on your side:

Markup:

<asp:ScriptManager runat="server" ID="ScriptManager1">
</asp:ScriptManager>
<telerik:RadAjaxManager ID="RadAjaxMgr" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadGrid ID="RadGrid1" AutoGenerateColumns="true" ShowHeader="true" runat="server" EnableLinqExpressions="false"
    Width="97%" GridLines="None" OnNeedDataSource="RadGrid1_NeedDataSource" OnDetailTableDataBind="RadGrid1_DetailTableDataBind">
    <MasterTableView Name="Master" DataKeyNames="EmployeeID, ReportsTo" GridLines="Both" PageSize="15"
        HierarchyDefaultExpanded="true" HierarchyLoadMode="ServerOnDemand">
        <SelfHierarchySettings KeyName="EmployeeID" ParentKeyName="ReportsTo" />
    </MasterTableView>
</telerik:RadGrid>

Code behind:

protected void Page_Load()
{
    //RadGrid1.MasterTableView.FilterExpression = "P_ID IS NULL"
    RadGrid1.MasterTableView.FilterExpression = "ReportsTo IS NULL";
}
protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
    // RadGrid1.DataSource = GetDataTable("SELECT ID, P_ID FROM MY_TB order by ordnl_pos ")
    RadGrid1.DataSource = GetDataTable();
}
public static DataTable GetDataTable()
{
    DataTable table = new DataTable();
    table.Columns.Add("EmployeeID", typeof(int));
    table.Columns.Add("Name");
    table.Columns.Add("ReportsTo", typeof(int));
    table.Rows.Add(1, "Name" + 1, 3);
    table.Rows.Add(2, "Name" + 2, 3);
    table.Rows.Add(3, "Name" + 3, null);
    table.Rows.Add(4, "Name" + 4, 2);
    table.Rows.Add(5, "Name" + 5, 2);
    table.Rows.Add(6, "Name" + 6, 3);
    table.Rows.Add(7, "Name" + 7, 3);
    table.Rows.Add(8, "Name" + 8, 2);
    table.Rows.Add(9, "Name" + 9, 3);
    return table;
}
protected void RadGrid1_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)
{
 
}

I hope this helps.

Regards,
Martin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Sharmili Rao
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or