I have used a simple tree view with check boxes. How can I get the object associated with a particular node on click ?
Also how can I access objects associateds with all the selected nodes(checkbox selection)?
My code is as below.
<%
=Html.Telerik().TreeView()
.Name(
"TreeView")
.ShowCheckBox(
true)
.ExpandAll(
true)
.BindTo(model, mappings =>
{
mappings.For<
TreeViewNodeData>(binding => binding
.ItemDataBound((item, treeViewNode) =>
{
item.Text = treeViewNode.NodeName;
})
.Children(child => child.ChildNodes));
mappings.For<
TreeViewNodeData>(binding => binding
.ItemDataBound((item, product) =>
{
item.Text = product.NodeName;
}));
})
.ClientEvents(events => events.OnSelect(
"Select"))
%>
14 Answers, 1 is accepted
Please reply to this thread its blocking our prototype development. Our telerik purchase is underway. :) Expecting quick reply.
Thanks,
Arun
This is not possible. What you can do is store the object key in the Value property of the node which you can later access. The whole object is not available as the treenode is not aware of it. Use the Value to retrieve the object of interest.
Looking forward to your purchase :)
All the best,
Atanas Korchev
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.
Thank you for your reply. I tried to use the value property of the treeview node. On click of the node I am trying to get the value as follows.
<
script type="text/javascript">
function Select(e) {
var treeview = $('#TreeView').data('tTreeView');
var value = treeview.getItemValue(e.item);
}
</
script>
When I run the code I get "Object doesn't support the property or method".
If i use the getItemText method, it works fine. The getItemValue doesnot work.
Please advice.
Kindly reply to my previous post with some example code. I am not able to use the getItemValue method. It is very urgent.
Thanks,
getItemValue was introduced with the 2009.1.309 version. Make sure you are using that version or later.
Regards,
Atanas Korchev
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.
I am using the 2010.1.309 version. This is what I got when I downloaded from Telerik website.
Please advice.
Hope to get your reply soon.
I am not really sure what the problem may be. You can try the following to see if the getItemValue method is available:
alert(treeview.getItemValue);
If this does not show a valid method then you are perhaps not using 2010.1.309. Ideally you can send us a sample project which demonstrates the problem at hand. Since the forum does not allow attachments you can host the project at some public location and send us a link.
Regards,
Atanas Korchev
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.
Is it possible for you to give us an email id? So that we can send the project to you?
Many thanks
You can send the project to atanas.korchev at telerik.com
Regards,
Atanas Korchev
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.
Thanks for the answer for getting the value of a tree view item.
I have two more queries. I am using checkboxes for each node in the tree view.
Some times I want to perform certain action on selected(checkbox selection) treeview nodes.
So how do I get access to the checkbox selected nodes? What property / method should I use?
If you could send us the code it will be very helpful. Also How can I capture the checked event?
I want to check / uncheck all the child nodes when the parent node is checked / unchecked.
Waiting for your reply. This will help us in the prototype, so that we can finalize on our purchase.
Best regards,
I have attached a simple test project, which shows how to check/uncheck parent and all child nodes. I believe that the implementation covers most of your questions.
All the best,
Georgi Krustev
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.
Thank you very much for the sample code for the checkbox support. It was very helpful. I was wondering if these features are available in MVC 1.0 as well?The sample project you sent uses MVC 2.0.
Could you please send us some thing for MVC 1.0 as we have not migrated to MVC 2 yet. The features that we need are
1. check / uncheck child nodes when a parent node is checked / unchecked.
2. Getting access to the checked nodes(to retrieve the value) in the controller.
Many thanks.
The implemented features are supported in MVC1. In general the functionality, which this simple project implements, does not depend in the version of the ASP.NET MVC framework. I believe you will be able to port it to ASP.NET MVC 1.0 without any troubles.
Kind regards,
Georgi Krustev
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.
@(Html.Telerik().TreeView()
.Name("TreeView")
.BindTo(Model, mappings =>
{
mappings.For<Category>(binding => binding
.ItemDataBound((item, category) =>
{
item.Text = category.CategoryName;
})
.Children(category => category.Products));
mappings.For<Product>(binding => binding
.ItemDataBound((item, product) =>
{
item.Text = product.ProductName;
}));
})
)
I attempted to add it to .ItemDataBound:
.ItemDataBound((item, category) =>
{
item.Text = category.CategoryName;
item.Value = category.CategoryID;
})
but that causes an error: "Delegate 'System.Action<Telerik.Web.Mvc.UI.TreeViewItem,NFRWebSandbox.Models.Project>' does not take 1 arguments"
How do I set Value to CategoryID?
Thanks.