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

DataItem is null

3 Answers 183 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
stephen cossgrove
Top achievements
Rank 1
stephen cossgrove asked on 17 Mar 2010, 01:54 PM
Hi, Here is my setup:
1. in the file

<

 

telerik:radtreeview id="RadTreeView2" runat="server" width="100%" height="100%"

 

 

datasourceid="ObjectDataSource1" datafieldid="ID" datafieldparentid="ParentID"

 

 

datatextfield="Text" OnNodeClick="RadTreeView2_OnNodeClick">

 

 

<DataBindings>

 

 

<telerik:RadTreeNodeBinding Expanded="true" />

 

 

</DataBindings>

 

</

 

telerik:radtreeview>

 

<

 

asp:ObjectDataSource ID="ObjectDataSource1" runat="server"

 

 

TypeName="xxxx.Component.Classes.SiteDataItemCache" SelectMethod="GetSiteDataItems">

 

</

 

asp:ObjectDataSource>
2. in the codebehind

 

protected

 

void RadTreeView2_OnNodeClick(object sender, RadTreeNodeEventArgs e)

 

{

 

SiteDataItem item = (SiteDataItem) e.Node.DataItem;

 

}


3. THE PROBLEM
the e.node.DataItem is always null.
Can anyone tell me why and how i can make this the SiteDateItem that is bound to the tree node?

3 Answers, 1 is accepted

Sort by
0
Vesko
Top achievements
Rank 2
answered on 17 Mar 2010, 02:38 PM
Hi,

this article should be of help:
Troubleshooting > The DataItem property is empty
0
stephen cossgrove
Top achievements
Rank 1
answered on 17 Mar 2010, 11:25 PM
OK, so  how do i get the object that is being bound on say the nodeclick event?

How do i get the id of the clicked node and it's parent node id?
0
Yana
Telerik team
answered on 19 Mar 2010, 08:59 AM
Hello stephen,

You should subscribe to OnNodeDataBound event and set the needed values as custom attributes of the nodes of the treeview, then you can get them without a problem in NodeClick event handler.

Kind regards,
Yana
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
TreeView
Asked by
stephen cossgrove
Top achievements
Rank 1
Answers by
Vesko
Top achievements
Rank 2
stephen cossgrove
Top achievements
Rank 1
Yana
Telerik team
Share this question
or