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

[Solved] Getting access to the objects bound to node

14 Answers 213 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Arun Prasath
Top achievements
Rank 1
Arun Prasath asked on 12 Apr 2010, 12:55 PM
Hi,
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

Sort by
0
Arun Prasath
Top achievements
Rank 1
answered on 16 Apr 2010, 10:33 AM
HI Atanas,

Please reply to this thread its blocking our prototype development. Our telerik purchase is underway. :) Expecting quick reply.

Thanks,
Arun
0
Atanas Korchev
Telerik team
answered on 16 Apr 2010, 11:09 AM
Hello Arun Prasath,

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.
0
Arun Prasath
Top achievements
Rank 1
answered on 19 Apr 2010, 07:48 AM
Hi Atanas,
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.


 

0
Arun Prasath
Top achievements
Rank 1
answered on 19 Apr 2010, 08:28 AM
Hi Atanas,
Kindly reply to my previous post with some example code. I am not able to use the getItemValue method. It is very urgent.

Thanks,
0
Atanas Korchev
Telerik team
answered on 19 Apr 2010, 09:14 AM
Hi Arun Prasath,

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.
0
Arun Prasath
Top achievements
Rank 1
answered on 19 Apr 2010, 09:28 AM
Hi Atanas,
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.
0
Atanas Korchev
Telerik team
answered on 19 Apr 2010, 09:58 AM
Hi Arun Prasath,

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.
0
Arun Prasath
Top achievements
Rank 1
answered on 19 Apr 2010, 11:00 AM
Hi,
Is it possible for you to give us an email id? So that we can send the project to you?

Many thanks
0
Atanas Korchev
Telerik team
answered on 19 Apr 2010, 11:21 AM
Hello Arun Prasath,

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.
0
Arun Prasath
Top achievements
Rank 1
answered on 21 Apr 2010, 07:53 AM
Hi Atanas,
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,
0
Georgi Krustev
Telerik team
answered on 21 Apr 2010, 08:36 AM
Hello Arun Prasath,

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.
0
Arun Prasath
Top achievements
Rank 1
answered on 23 Apr 2010, 11:30 AM
Hi,
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.
0
Accepted
Georgi Krustev
Telerik team
answered on 23 Apr 2010, 12:03 PM
Hi Arun Prasath,

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.
0
Don
Top achievements
Rank 1
answered on 28 Mar 2011, 07:06 PM
How do you bind the Value property to an ID field when using the Binding to Model approach (hierarchical TreeView)?  In the example project, DataBindingToModel.cshtml contains:

@(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.
Tags
TreeView
Asked by
Arun Prasath
Top achievements
Rank 1
Answers by
Arun Prasath
Top achievements
Rank 1
Atanas Korchev
Telerik team
Georgi Krustev
Telerik team
Don
Top achievements
Rank 1
Share this question
or