How to get Hierarchy Node levels of a Telerik treeview - c#

Hi I am populating an dynamic XML file into telerik treeview as hierarchy tree view as below.
Modules //root node
* Organization //Parent node
*Policy //Child of Organization
*Transports
* Employess
*Salary
* Rewards
*Winners
When i am going to select Modules-> Organization -> Policy , I want to get this hierarchy in my client event but Now I am getting the last node value only as "Policy". I want to get the full path of this herarchy.
And my client event code is:
function onSelect(e) {
debugger;
var tv = $('#HierarchyView').data('tTreeView');
var file = tv.getItemValue(e.item); // Here I am getting the last node name as "Policy", I want to get it as Modules-> Organization -> Policy
var nodeElement = e.item;
}
Can anyone please tell me the way to get that Hierarchy? Its Urgent.
Thanks.

This is the solution:
Telerkik Documentation for Node Path with javascript
regards

Related

Umbraco: Get root Node ID based on Node ID

I'm new to Umbraco, the issue that I have a 5 root nodes, and I've got a list of random pages that are contained within those root nodes. The data I'm receiving back from these pages are NodeId, NodeName and Level. What I'm trying to do is get root node information for each of the pages I have. Unfortunately this is where I'm getting issues, is there a way to get the root node or level 1 node's information based on a NodeId.
This is what I've got so far:
foreach (var item in pages)
{
int level = item["level"].AsInt();
if (level > 1){
var currentItem = library.GetCurrentDomains(item.Id);
}
}
Ive tried library.GetCurrentDomains(item.Id) however this doesnt work.
Not entirely sure if this is what you need, nor if it's the best way, but you could do something like
item.Path.Split(',')[1]
to get the second level "root" of any node. I think ;-)
Assuming the list of random pages are all IPublishedContent, you can use the extension method AncestorOrSelf(1) on the page, which will get the root node for the page. E.g.
foreach (var item in pages)
{
var rootPage = item.AncestorOrSelf(1);
//do something with the root node here
}

Umbraco 4.11 get Parent Node

Should be a simple answer.
I am using Umbraco 4.11 and I need to get the parent Node of a cast node. I am a bit of a noob to C# and I am fixing a control someone else made. Should be simple but it was originally written before the DLL update from 4.7 to 4.11.
So below is my code. I need to get the parent Node. What would be the correct syntax to do this. You can see where the old code is commented out.
Thanks in advance.
//New using
using umbraco.NodeFactory;
private string GetEmailContactProperty()
{
Node node = Node.GetCurrent();
string email = null;
do
{
if (node.NodeTypeAlias == NodeTypeAlias)
{
email = node.GetProperty("emailContact").Value;
if (!String.IsNullOrEmpty(email))
break;
}
//node = node.Parent;
//***Need Parent Node here. new Node is asking for Overload.
node = new Node().Parent;
} while(node.Parent.Id > -1);
The original code should do what you are asking with regards to getting the parent node.
node = node.Parent;
Basically, from your code you want to traverse up the tree, across your ancestors, to find a property named "emailContact" that is not IsNullOrEmpty.
I think what you are looking for is a piece of code like this:
var emailContact = CurrentModel.AncestorsOrSelf().Items.Where(n => !string.IsNullOrWhiteSpace(n.GetProperty("emailContact").Value))
Another way would be to get property with the recursive flag set to true like so:
var emailContact = Model.GetProperty("emailContact ", true).Value;
(See this post: http://our.umbraco.org/forum/developers/razor/19005-Recursive-fields-using-Razor-macro?p=1)
On a side not, it looks like you are currently working with Documents and not "content nodes", is this a back office control or a front end control?
Hope this helps

How to find out the parent page Id from IPageStructure? (Composite C1)

Is this the best way to get the parentId of a page from the IPageStructure in Composite C1 within a UserControl ?
string pPageId = SitemapNavigator.CurrentPageId.ToString();
Guid parentId = connection.Get<IPage>().Where(p => p.Id == new
Guid(pPageId)).First().GetParentId();
I do use the present pageId as a string, which helps in the above case seeing as .First() can't be used on Guid.
Take a look at the SitemapNavigator instance class you can grab from DataConnection - when you get the data bound instance it gives you access to the current page in form of a PageNode class from which you can access parent, child pages. You also have access to titles, descriptions etc.
// General (verbose) example - getting parent page ID
using (var connection = new DataConnection())
{
var currentPageNode = connection.SitemapNavigator.CurrentPageNode;
var parentPageNode = currentPageNode.ParentPage;
var parentPageId = parentPageNode.Id;
}
If you are doing this from a Razor Function there is already a data connection available (this.Data) so the above can be written like this:
// Razor example - getting parent page ID
var parentPageId = Data.SitemapNavigator.CurrentPageNode.ParentPage.Id;
One option is just to rely 100% on the standard asp.net way using the SiteMapProvider functionality.
Get a specific node like this: var node = SiteMap.CurrentProvider.FindSiteMapNodeByKey("...").
Get the Parent node like this: var parentNode = node.ParentNode.
Get its id like this: var id = parentNode.Key

Umbraco: Get "Last Edits" values from content

In my umbraco project, i require values in the "last Edited" tab, inside C# code.
How can i get those values?
Please Help,
Thanks.
It's quite simple. Here's one way of doing it:
// Assure the query is done to the root node, in this case I was on the root controller.
var recentUpdatedNodes =
Model.Content.DescendantsOrSelf().OrderByDescending(x =>
x.UpdateDate).Take(50);
foreach (var node in recentUpdatedNodes)
{
#node.Name
#node.Url
#node.Id
}

TreeNode key issue

I am using TreeView control in WinForm.
I am trying to use the following code, but getting "NullReferenceException".
I am following the syntax provided i.e. tree.Nodes[key].Nodes.Add(key,text)
I don't know whats wrong with the code.
Please have a look at the code i used -
tvTree.Nodes.Add("Subjects", "Subjects");
tvTree.Nodes["Subjects"].Nodes.Add("Physics", "Physics");
tvTree.Nodes["Physics"].Nodes.Add("PhysicsP1", "Paper1");
tvTree.Nodes["Physics"].Nodes.Add("PhysicsP2", "Paper2");
tvTree.Nodes["Physics"].Nodes.Add("PhysicsP3", "Paper3");
Thanks for sharing your time.
Your problem is that the "Physics" nodes are not direct children of tvTree but instead are children of the "Subjects" node. What should make this easier is that TreeNodeCollection.Add returns a TreeNode that you can reference later on.
var subjects = tvTree.Nodes.Add("Subjects", "Subjects");
var physics = subjects.Nodes.Add("Physics", "Physics");
physics.Nodes.Add("PhysicsP1", "Paper1");
physics.Nodes.Add("PhysicsP2", "Paper2");
physics.Nodes.Add("PhysicsP3", "Paper3");
If you only have the name, you can use Find:
var parentName = "from wherever";
var parentNodes = tvTree.Nodes.Find(parentName, true);
/* handle multiple results */
/* add children */
Also you may achieve this with
tvTree.Nodes.Add("Subjects", "Subjects");
tvTree.Nodes["Subjects"].Nodes.Add("Physics", "Physics");
var phyNode = tvTree.Nodes.Find("Physics", true).First();
phyNode.Nodes.Add("PhysicsP1", "Paper1");
phyNode.Nodes.Add("PhysicsP2", "Paper2");
phyNode.Nodes.Add("PhysicsP3", "Paper3");
You can use this
tvTree.Nodes["Subjects"].Nodes["Physics"].Add("PhysicsP1", "Paper1");

Categories