Telerik
Skip Navigation LinksHome / Community / Forums / ASP.NET AJAX > TreeView > Question about accessing information off server-side NodeClick event...

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

Feed from this thread
  • J Intermediate avatar

    Posted on Jul 1, 2009 (permalink)

    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

    Reply

  • Telerik Admin admin's avatar

    Posted on Jul 1, 2009 (permalink)

    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.

    Reply

  • J Intermediate avatar

    Posted on Jul 1, 2009 (permalink)

    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?

    Reply

  • Telerik Admin admin's avatar

    Posted on Jul 1, 2009 (permalink)

    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.

    Reply

  • J Intermediate avatar

    Posted on Jul 1, 2009 (permalink)

    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

    Reply

  • Answer Telerik Admin admin's avatar

    Posted on Jul 1, 2009 (permalink)

    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.

    Reply

  • J Intermediate avatar

    Posted on Jul 1, 2009 (permalink)

    Thanks again Albert, you were right yet again!

    J

    Reply

Back to Top

Skip Navigation LinksHome / Community / Forums / ASP.NET AJAX > TreeView > Question about accessing information off server-side NodeClick event...
Related resourses for "Question about accessing information off server-side NodeClick event..."

ASP.NET TreeView Features  |   Documentation   |  Demos  |  Telerik TV  |  Self-Paced Trainer  |  Step-by-step Tutorial  ]

Powered by Sitefinity ASP.NET CMS

Contact Us | Site Feedback | Terms of Use | Privacy Policy
Copyright © 2002-2010 Telerik. All rights reserved.