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

Question about accessing information off server-side NodeClick event...

6 Answers 118 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
J
Top achievements
Rank 1
J asked on 01 Jul 2009, 01:03 PM
I have the following control
<telerik:RadTreeView   
    ID="radtree" runat="server" 
    OnDataBound="radtree_DataBound" OnDataBinding="radtree_DataBinding"   
    OnNodeExpand="radtree_NodeExpand" 
    EnableEmbeddedBaseStylesheet="False" EnableEmbeddedSkins="False" 
    Skin="SomeSkin" OnNodeClick="radtree_NodeClick" 
    >      
    <CollapseAnimation Duration="100" Type="OutQuint" /> 
    <ExpandAnimation Duration="100" /> 
</telerik:RadTreeView> 

And here is my code behind for the event OnNodeClick:
protected void radtree_NodeClick(object sender, RadTreeNodeEventArgs e)  
{  
    RadTreeView node = (RadTreeView)sender;  

if i have defined my radtree.DataFieldID to some value is there a way in the NodeClick event to access that particular nodes DataField value?  I tried to do:
node.DataFieldID 

but this just returns the string of the column name not any particular unique id.

J

6 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 01 Jul 2009, 01:33 PM
Hello J,

DataFieldID is only used for databinding purposes. You can use DataValueField instead. Then use the Value property of the node to access the associated unique value.

protected void radtree_NodeClick(object sender, RadTreeNodeEventArgs e) 

    RadTreeNode node = e.Node;
    string value = node.Value
}

Greetings,
Albert
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
J
Top achievements
Rank 1
answered on 01 Jul 2009, 03:12 PM
Thank you for the reply Albert but in my NodeClick event I get an error when I do

    protected void radtree_NodeClick(object sender, RadTreeNodeEventArgs e)  
    {  
        RadTreeNode node = (RadTreeNode)sender;  
    } 

The error says: "Unable to cast object of type 'Telerik.Web.UI.RadTreeView' to type 'Telerik.Web.UI.RadTreeNode'.", my first thought is that I am using an 'older' version of Telerik.Web.UI.dll (2008.2.723.20 to be exact) and to update to a new dll. 

But in the mean time, does my version support casting the sender object to a RadTreeNode instead of RadTreeView?
0
Atanas Korchev
Telerik team
answered on 01 Jul 2009, 03:16 PM
Hello J,

The sender argument is the treeview which fires the NodeClick event and it cannot be cast to RadTreeNode. Use the Node property of the RadTreeNodeEventArgs argument to get the clicked node.

Regards,
Albert
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
J
Top achievements
Rank 1
answered on 01 Jul 2009, 03:44 PM
Thanks again for your help Albert.  I can indeed access the node's value property when I do:

    protected void radtree_NodeClick(object sender, RadTreeNodeEventArgs e)  
    {  
        string test = e.Node.Value;  
    } 

While it does work, I was hoping to get the pk associated with this particular node in the original DataTable.  When I set up my RadTreeView before databinding I set the following properties:
DataSet TreeData = fnGetData();  
 
radtree.DataTextField = "ENTITYNAME";  
radtree.DataValueField = "ENTITYNAME";  
radtree.DataFieldID = "PK";  
radtree.DataFieldParentID = "PARENTPK";  
radtree.DataSource = TreeData;  
radtree.DataBind(); 

See how radtree.DataFieldID is set to the value in column "PK", can RadTreeNodeEventArgs.Node access that nodes PK value on the NodeClick event?  You've shown me that it can access the column "ENTITYNAME" via the property DataValueField.

J
0
Accepted
Atanas Korchev
Telerik team
answered on 01 Jul 2009, 03:46 PM
Hi J,

If you configure the treeview like this:

radtree.DataTextField = "ENTITYNAME"; 
radtree.DataValueField = "PK"; 
radtree.DataFieldID = "PK"; 
radtree.DataFieldParentID = "PARENTPK"; 
radtree.DataSource = TreeData; 
radtree.DataBind();

You would be able to get the primary key from the Value property.

Sincerely yours,
Albert
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
J
Top achievements
Rank 1
answered on 01 Jul 2009, 05:30 PM
Thanks again Albert, you were right yet again!

J
Tags
TreeView
Asked by
J
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
J
Top achievements
Rank 1
Share this question
or