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

[Solved] Self-Referencing Heirarchy Problem

5 Answers 159 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Levi
Top achievements
Rank 1
Levi asked on 14 Oct 2009, 02:47 PM
I'm trying to use this example, but cannot get it to work:
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/selfreferencing/defaultcs.aspx

I'm thinking it's related to the filter in the page load. I'm using a list rather than a database table, and it check for dbnull. I tried using an empty string, but the grid doesn't come up at all when I do.

My list structure is like this:
        class fooMetrics
        {
            public string Metric { get; set; }
            public string CurrentValue { get; set; }
            public string PreviousValue { get; set; }
            public string Change { get; set; }
            public string Category { get; set; }
        }

Here is the page load reference I am referring to:
        protected void Page_Load(object sender, EventArgs e)
        {
            ScriptManager.RegisterClientScriptInclude(this, this.GetType(), "script1", ResolveUrl("~/js/KeyPerformanceIndicators.js"));

            if (Assembly.GetAssembly(typeof(ScriptManager)).FullName.IndexOf("3.5") != -1)
            {
                gridConversion.MasterTableView.FilterExpression = @"it[""Category""] = Convert.DBNull";
            }
            else
            {
                gridConversion.MasterTableView.FilterExpression = "Category IS NULL";
            }
        }

This line is what causes the grid to disappear:
  gridConversion.MasterTableView.FilterExpression = @"it[""Category""] = Convert.DBNull";

Any ideas? My category field would be an empty string if there is no parent.















5 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 19 Oct 2009, 01:29 PM
Hello Levi,

If you are using a collection of custom objects (e.g. List<fooMetrics>), your Linq expression needs to directly reference the Category property:

"it.Category != \"\""

Your standard SQL-style expression would be:

"([Category] <> '')"

These two expressions assume, as you said that your values may be empty string, but not null.

Kind regards,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Levi
Top achievements
Rank 1
answered on 19 Oct 2009, 08:16 PM

I am no longer getting an error, but the results do not seem to be filtering. Here is the full statement:
gridConversion.MasterTableView.FilterExpression = "it.Category != \"\"";

Am I missing something?

My object list is setup like so:

  List<fooMetrics> data;  
                data = new List<fooMetrics>();  
                data.Add(new fooMetrics() { Metric = "Parent"CurrentValue = "82"PreviousValue = "26"Change = "-12%"Category="" });  
 
                data.Add(new fooMetrics() { Metric = "Child 1"CurrentValue = "$293"PreviousValue = "300"Change = "-12%"Category = "Parent" }); 
                data.Add(new fooMetrics() { Metric = "Child 2"CurrentValue = "$293"PreviousValue = "300"Change = "-12%"Category = "Parent" }); 

When the grid loads I am getting all of the items as root nodes rather than just "Parent Item". Any ideas?

Thanks for your help,
Levi
0
Veli
Telerik team
answered on 21 Oct 2009, 06:24 AM
Hello Levi,

The relation between your items seems to be reordered compared to what I first thought. So, your parent item is a Metric that has a category of "", while the child items need to have the Metric of the parent as value in their Category field.

If this is the correct logic now, you need to set the hierarchy settings in the following way:

<SelfHierarchySettings ParentKeyName="Category" KeyName="Metric" />

Additionally, your filter expression needs to filter out those items from the master table, that have a value in their Category field, leaving the ones that do not have a value:

if (Assembly.GetAssembly(typeof(ScriptManager)).FullName.IndexOf("3.5") != -1)
{
   RadGrid1.MasterTableView.FilterExpression = "it.Category == \"\"";
}
else
{
    RadGrid1.MasterTableView.FilterExpression = "([Category] = '')";
}

I am attaching a sample page you can test.

Kind regards,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Krishnan LN
Top achievements
Rank 1
answered on 25 Feb 2010, 08:06 AM
Unfortunately this is not working for me. I have a name field and parentname field.

Following is my settings in client-side
<telerik:RadGrid ID="RadGrid1" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="True"   
     OnNeedDataSource="RadGrid1_NeedDataSource" OnColumnCreated="RadGrid1_ColumnCreated" OnItemCreated="RadGrid1_ItemCreated" OnItemDataBound="RadGrid1_ItemDataBound">  
            <MasterTableView HierarchyDefaultExpanded="true" HierarchyLoadMode="Client" AllowSorting="true" 
                DataKeyNames="ParentName,Name" Width="100%">  
                <SelfHierarchySettings ParentKeyName="ParentName" KeyName="Name" /> 
Following is my filter expression

public void Page_Load(object sender, EventArgs e)  
        {  
            if (Assembly.GetAssembly(typeof(ScriptManager)).FullName.IndexOf("3.5") != -1)  
            {  
                RadGrid1.MasterTableView.FilterExpression = "it.ParentName == \"\"";  
            }  
            else 
            {  
                RadGrid1.MasterTableView.FilterExpression = "([ParentName] = '')";  
            }  
        } 

When i run the application, im getting a child row duplicated in parent level. find the attached output.

0
Veli
Telerik team
answered on 25 Feb 2010, 11:56 AM
Hello Krishnan LN,

It seems the rows that have no value for ParentName do not get filtered out of the parent table. Have you tried with null value filtering like it is shown in the selft-referencing hierarchy help article:

public void Page_Load(object sender, EventArgs e)
       {
           if (Assembly.GetAssembly(typeof(ScriptManager)).FullName.IndexOf("3.5") != -1)
           {
               RadGrid1.MasterTableView.FilterExpression = @"it[""ReportsTo""] = Convert.DBNull";
           }
           else
           {
               RadGrid1.MasterTableView.FilterExpression = "ReportsTo IS NULL";
           }
       }


Sincerely yours,
Veli
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
Levi
Top achievements
Rank 1
Answers by
Veli
Telerik team
Levi
Top achievements
Rank 1
Krishnan LN
Top achievements
Rank 1
Share this question
or